Я хочу загрузить эту библиотеку классов :
namespace ClassLibrary1
{
public class Class1
{
public Class1()
{
}
public static int Sum(int a, int b)
{
return a + b;
}
}
}
У меня есть wcf service , который возвращает мне массив byte[]
(ClassLibrary1 ) я не могу загрузить эту сборку
static void Main(string[] args)
{
FileTransferService.ApplicationHostServiceClient client = new FileTransferService.ApplicationHostServiceClient();
FileTransferService.AssemblyPackage[] asmbs = client.GetFile();
//var newDomain = AppDomain.CreateDomain("FooBar", null, null);
foreach (FileTransferService.AssemblyPackage item in asmbs)
{
byte[] mybuffer = item.Buffer;
new AssemblyLoader().LoadAndCall(mybuffer);
}
}
public class AssemblyLoader : MarshalByRefObject
{
public void LoadAndCall(byte[] binary)
{
Assembly loadedAssembly = AppDomain.CurrentDomain.Load(binary);
object[] tt = { 3, 6 };
Type typ = loadedAssembly.GetType("ClassLibrary1.Class1");
MethodInfo minfo = typ.GetMethod("Sum", BindingFlags.Public);
int x = (int)minfo.Invoke(null, tt);
Console.WriteLine(x);
}
}
Ошибка, возвращаемая мне в этом методе: AssemblyloadedAssembly = AppDomain.CurrentDomain.Load (binary);
ОШИБКА:
BADIMAGEFORMAT EXCEPTION
Could not load file or assembly '4096 bytes loaded from Client2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
ИСКЛЮЧЕНИЕ:
Bad IL format
У меня ошибка такого рода, но нет точного решения.я хочу загрузить свою сборку, используя AppDomain.