Search code examples
c#dllfileloadexception

FileLoadException with new version of dll


I have an application that needs to work with two versions of a dll. I figured I would just compile the app once, copy the exe to two directories, and then copy the two versions of the dlls to each of these directories. FYI, I'm not doing anything with the GAC. However, I'm getting a FileLoadException on the version with the dll it was not compiled with.

In the project, I have the "Specific Version" set to false for the dll reference. But, maybe that is the wrong setting. How do I get this to work with multiple versions?


Solution

  • I ruled against changing the config file, simply because it's another thing I would need to do. In regards to the address changing for different versions of the dll, I don't think I have that problem since I am actually using an interface to call my methods.

    To give a little more detail, I simply need to create an instance of one type in multiple dlls. From there, I treat it as an interface object. So, here is my solution:

    Assembly asm = Assembly.LoadFrom("XXX.YYY.ZZZ.Bin.dll");
    Type type = asm.GetType("MyType");
    IMyType obj = Activator.CreateInstance(type) as IMyType;
    

    This seems to work.