I am building a C# .net 3.5 application.
I have an exe ‘MainApp’ which references a dll ‘CommonDll’
The CommonDll dynamically loads another dll ‘LoadedDll’ and invokes dynamically a method called func().
The ‘LoadedDll’ references the ‘CommonDll’
in the ‘CommonDll’ there is a method foo() which the func() is calling.
func()
{
foo();
}
So, what we have so far:
MainApp ==> CommonDll ==Dynamicly==> LoadedDll
LoadedDll ==> CommonDll.
everything worked just fine, until I changed the method foo() to get a boolean argument: foo(bool val); and cheanged also the func() in ‘LoadedDll’ to
func()
{
foo(true);
}
I have the MainApp(references the old CommonDll) in version 1.0, and the LoadedDll(references the new CommonDll) in version 1.1
For some reason I get a “MethodNotFound Excepion” on the method foo saying it cannot find foo that gets a boolean argument.
Why is this happening? The LoadedDll is using a static reference to the updated CommonDll, so why it can’t find that method?
Also, the exception doesn’t saying that it cannot find the ‘func()’ method which is loaded dynamically, but it says that it cannot find the foo method.
EDIT:
I looked for the dll in the GAC but it is not there, is there another reason why an old dll that is already in the memory will be loaded instead of the new one?
I figured out the reason for the issue.
there was some external code which cahnged the dll version to a constant value and therefore the strong name was the same.
buttom line: if you are load a dll and then you try to load another dll with the same strong name, the first dll will be used.
inorder to load 2 dlls with the same name they must have a different strong name.