Question

I have an program which calls a msi installer. After the msi package is installed successfully I tried to load a assembly which was added by the msi package in the GAC. I am not able to load the assembly but this particular assembly is being added to the GAC. When i run the program for the second time the assembly gets loaded properly. here is the pseudocode

load assembly(assemblyname)
{
 if(!Assembly.load(assemblyname))
 msi.install();
 Assembly assembly =Assembly.load(assemblyname)
 if(assembly == null)
  console.writeline("assembly not loaded"); 
}

If the msi package is not installed already , i always get assembly not loaded for the first time when I run this function. Somehow I think this is related to the GAC list which is present before the program gets executed. Is there a way where I can reload this?

Was it helpful?

Solution

The pseudo code as posted will certainly fail. The CLR remembers previous Assembly.Load() failures and will fail them consistently afterwards, even if the assembly became available.

It isn't clear why you attempt to load the assembly again. Get ahead by either assuming it is properly installed if the install didn't fail or just always install and leave it up to the installer to detect that the assembly is already present. If that's not practical then you need to use the IAssemblyCache interface to check for presence, QueryAssemblyInfo() method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top