In .NET, how can I detect whether a user has a specific redistributable installed?

Go To


I have created a class which builds a Crystal report and displays it in a report viewer.

However, without the Crystal Redistributable, the code crashes. How can I programatically detect whether the end-user has the Crystal DLL installed?

The code I am required to include is:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
2009-06-16 13:56
by Jon Winstanley


I suppose Crystal installs to GAC. So you need to programmatically browse Global assembly cache and look for Crystal assembly there

GAC can be programmatically managed thru Windows API. Here you will find a simple wrapper that allows to manage GAC from a managed code

But I would not recommend you to go this way. :)

The good solution is usually too check for all required assemblies during the installation of your software, I suppose Windows Installer has functions to check for assemblies

However, it is not always OK. Suppose if you would like users to run your program even without Crystal, but do not allow show reports if Crystal is not installed.

In this case you should decouple all Reports functionality from other forms. You should create a separate project with Crystal Reports functionality, let's call it MyReports. Only that project should reference to Crystal assemblies, while other should not. Other projects also should not directly reference to MyReports.

And finally you should use reflection to call a report viewer that is implemented inside MyReports from other projects.

Usually you will write try / catch around the procedure where you will use reflection to load MyReports assembly from file. So, if Crystal or something else not exist, it will throw exception, you will display it to user, but the other parts of the program will work.

Also, you can read about Dependency Injection design pattern, it helps to manage such problems.

2009-06-16 14:16
by Bogdan_Ch


Ideally, you would take care of all of the dependencies of your application at install time and make sure that all the the required components are already installed. However you can wrap your code that makes calls to the DLLs in question in a try..catch block and catch the DllNotFoundException when it gets thrown.

2009-06-16 14:00
by heavyd


You could check if the following registry key exists

HKEY_CURRENT_USER\Software\Crystal Decisions

This will tell you if crystal reports is installed. if you want to check a particular version check the child key. For instance the crystal reports installed with Visual Studio 2008 is 10.2

2009-06-16 14:26
by Rad


You can find out these details by looking into the registry. I will search and provide an update.

Edit: You could also include Crystal reports as a prerequisite in the deployment package. You can then be sure that the final user has the library.

2009-06-16 14:01
by AlexDrenea


Use a merge module with your setup. Sap have a list here:

Merge modules

2009-06-16 14:04
by RichardOD
The link is broke - Jon Winstanley 2009-09-09 12:33