I'm trying to load an assembly from a string-based stream in Cecil, however I keep getting System.BadImageFormatException
and I can't seem to figure out what I'm doing wrong.
What I'm trying:
var data = File.ReadAllText("/path/to/dll");
using(Stream s = StreamFromString(data)) {
var module = ModuleDefinition.ReadModule(s);
}
And StreamFromString
is defined as:
return new MemoryStream(Encoding.UTF8.GetBytes(s ?? ""));
I've also tried:
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
Using latest Cecil, .NET 4.5 on Windows Server 2012. Any ideas? Thanks :)
Edit: ModuleDefinition.ReadModule("/path/to/dll")
works fine so it's not a corrupt dll issue.
我不完全确定它为什么能工作-但是使用File.ReadAllBytes
读入字节数组并直接写入MemoryStream
而不使用StreamWriter
似乎已经解决了它。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.