NET文件从内存使用Assembly.Load()函数,但当我将我的字节数组提供给此函数时,我得到了一个名为BadImageFomatException的重复类型...在汇编中。

我的代码是:
try{
// prepare the Form to show balloontip
frmDefault frm = new frmDefault();
// prepare to load the application into memory (using Assembly.Load)
// read the bytes from the application exe file
FileStream fs = new FileStream(filePath, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length));
fs.Close();
br.Close();
// load the bytes into Assembly
Assembly a = Assembly.Load(bin);
// search for the Entry Point
MethodInfo method = a.EntryPoint;
if (method != null)
{
// create an istance of the Startup form Main method
object o = a.CreateInstance(method.Name);
Console.Write("Application started!");
method.Invoke(o, null);
}
else
{
// impossible to launch the application
Console.Write("Application error!");
}
}
catch
{
}发布于 2016-04-25 02:30:36
首先:
//从应用程序可执行文件中读取字节FileStream fs = FileStream(filePath,FileMode.Open);BinaryReader br =新BinaryReader(fs);byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length));fs.Close();br.Close();//将字节加载到程序集a= Assembly.Load(bin);
可以替换为:
var a = Assembly.LoadFile(filePath);关于这个问题,你似乎从同一个二进制文件中加载了两个不同的版本。从加载文件的位置加倍。
https://stackoverflow.com/questions/36826810
复制相似问题