-1

I have 2 assembly should be loaded from memory, I use the following code to implement it but it can't work. Help me, Thank you!

        Assembly.Load(File.ReadAllBytes("b.dll"));
        var assembly = Assembly.Load(File.ReadAllBytes("a.dll"));//a.dll referenced b.dll
        var type = assembly.GetTypes().First(p => p.FullName == "Namespace1.Type1");
        type.GetMethod("StaticMethod1", BindingFlags.Static | BindingFlags.Public).Invoke(null, new object[] { });//it throw an exception, can't load file or assembly b.dll
Jester
  • 56,577
  • 4
  • 81
  • 125
zEvolution
  • 49
  • 4

1 Answers1

0

Using Assembly.Load to load an assembly from a byte array, loads the assembly but does not register it under its name in the Application Domain. In order to provide your own assembly from a byte array when the runtime is looking to load a specific assembly with a specific name, you implement the AppDomain.AssemblyResolve event.

See this question and the answer for example code.

Community
  • 1
  • 1
NineBerry
  • 26,306
  • 3
  • 62
  • 93