DLL in the GAC Ignored after ResolveEventHandler Added

50 Views Asked by At

I was asked to debug a .NET Framework C# program OurProgram. I am told that it worked in the past. OurProgram uses methods from DLLs added to the global assembly cache (GAC) by another product's setup, e.g., DllInGac.dll.

At the beginning of execution, OurProgram calls AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(OurResolveEventHandler);. Later in execution, OurProgram can instantiate an object from class OtherClass in DllInGac.dll. However, when OurProgram calls a method on the object, OurResolveEventHandler is called, and an exception occurs because OurResolveEventHandler does not return DllInGac.dll.

If I add code to instantiate an object from OtherClass before OurProgram calls ...AssemblyResolve += new ResolveEventHandler(... and if the code also calls a method on the object, then in code executing after ...AssemblyResolve += new ResolveEventHandler(..., instantiating OtherClass and calling one of its methods is successful, and OurResolveEventHandler is not called.

Based on e.g., How the Runtime Locates Assemblies, I did not think that ResolveEventHandler is supposed to make the GAC be ignored. I would not think that the way to fix this problem is kludgily to instantiate an object from every needed DLL in the GAC and call a method on the object during OurProgram's initialization. I would be grateful to learn how to make adding a ResolveEventHandler not cause DllInGac.dll in the GAC to be ignored.

0

There are 0 best solutions below