mardi 15 septembre 2015

ReflectionTypeLoadException when the type is in AppDomain

I need to load some Assemblies via reflexion to my application. I have two folders with two version of base assembly (contain a abstract class) and ImplementVersion01.dll and ImplementVersion02.dll.

I load this assembly via method Assembly.LoadFile. In enumeration of assemblies (AppDomain.CurrentDomain.GetAssemblies()) i see both version of base assembly, but when i am trying to get types of ImplementVersion01.dll or ImplementVersion02.dll i get an error:

System.Reflection.ReflectionTypeLoadException

My code is:

string req01DirPath = @"c:\data\AppV1\";
string req02DirPath = @"c:\data\AppV2\";

Assembly app1 = null;
Assembly app2 = null;

foreach (string filePath in Directory.GetFiles(req01DirPath, "*.dll"))
{
    if (filePath.Contains("ImplementVersion01.dll"))
        app1 = Assembly.LoadFile(filePath);
    else
        Assembly.LoadFile(filePath);
}

foreach (string filePath in Directory.GetFiles(req02DirPath, "*.dll"))
{
    if (filePath.Contains("ImplementVersion02.dll"))
        app2 = Assembly.LoadFile(filePath);
    else
        Assembly.LoadFile(filePath);
}

if (app1 != null && app2 != null)
{
    var types1 = app1.DefinedTypes;
    var types2 = app2.DefinedTypes;
}

in folder C:\data\AppV1\ is first version of base assembly and in c:\data\AppV2\ is the second version of base assembly.

Why i get an error when the both of version of base assembly is loaded in AppDomain?





Aucun commentaire:

Enregistrer un commentaire