Assembly Resolve Not Fully Loading My DLL?
I'm using a method to load a dll on an AssemblyResolve event. It's not quite working the way I want it to. Here's some code:
in my form load:
var a = AppDomain.CurrentDomain;
a.AssemblyResolve += (object sender, ResolveEventArgs args) => LoadDLL(sender, args, anArg);
LoadDLL:
public Assembly LoadDLL(object sender, ResolveEventArgs agrs, bool anArg){
//Let's just ignore anArg, it doesn't affect anything related to the problem
asseblyPath = @"XXX";//path to my dll
return Assembly.LoadFrom(assemblyPath);
}
So that's all well and good. I set Copy Local to false for my DLL so the AssemblyResolve event is called and I can load the desired version of my DLL.
One strange thing that is happening is this: After running this code, my code tries to access a public variable from a class containing global constant values (this class should be in my DLL).
public class GCV{
public GCV(){}
public string value1= "asdf";
}
Unfortunately, when I'm in debug mode, GCV.value1 is set to null when it clearly has a value in th开发者_JS百科e class definition. This is one symptom that I can describe here, hopefully enough to diagnose the problem?
Thanks!
It seems that in debug the version loaded differ from the one it load in release. Try to look in the Output folder when debugging, and look for the Loaded .... to find your dll. This should point to a different version that the one you expect.
精彩评论