My .net program is using an assembly, which should be installed in the GAC.
If the assembly is properly installed, it will be loaded as soon as I use it the first time, which is great. If, for example, I use a type from the assembly like this:
ESRI::ArcGIS::esriSystem::AoInitialize^ aoi = gcnew ESRI::ArcGIS::esriSystem::AoInitializeClass();
The assembly will be loaded.
Now sometimes the assembly will not be present in the GAC, and I need the program to be aware of this but not crash.
I tried wrapping the usage of the assembly into a try/catch block like this:
try
{
ESRI::ArcGIS::esriSystem::AoInitialize^ aoi = gcnew ESRI::ArcGIS::esriSystem::AoInitializeClass();
}
catch (System::Exception^ )
{
// assembly not found
}
But the program will not throw an exception but crash instead.
How can I check in advance, if the assembly is in the GAC and could be used without crashing? Or how could I catch the crash and disable the corresponding menu items in my program?