問題描述
無法加載混淆程序集 (Cannot load obfuscated assembly)
我是第一次使用 dotfuscator。我的項目是用 C# 和 .NET 3.5 編寫的,它有一個主程序和一些插件;這是加載插件的代碼片段:
// Load the file
Assembly asm = Assembly.LoadFile( pluginPath );
// Instantiate the types I need
foreach( Type type in asm.GetTypes() )
{
...
}
現在的問題是:如果我不混淆一切都很好,但是當我使用 dotfuscator asm.GetTypes()
時會拋出一個 ReflectionTypeLoadException,上面寫著
找到的程序集的清單定義與程序集引用不匹配。(來自 HRESULT 的異常:0x80131040)
我用谷歌搜索了幾個小時沒有結果。提前致謝。
編輯:經過一些研究和調試,我認為這是清單中的問題,因為反射無法看到(或加載)程序集中的類型. 我用 Reflector 打開了混淆程序集,但一切似乎都很好。
參考解法
方法 1:
Are your assemblies strong named or Authenticode signed? Obfuscation changes the structure of the assemblies and in order to use them after obfuscation you need to resign them.
The commercial versions of Dotfuscator supports the resigning of assemblies (both strong name and Authenticode) while if you are using the free Community Edition you will need to resign as a post build step in Dotfuscator.
方法 2:
Obfuscation works, in part, by renaming some or all method names, type names, etc.
Reflection can often fail when obfuscation is used. If you're lucky, you can be selective when it comes to choosing what to obfuscate, but this requires some attention to detail.
方法 3:
I don't think Obfuscation works well with reflection. In fact, I think that's the number one trade off when using obfuscation.
See this link for how to overcome types that need to be reflected over
(by Fabrizio、Joe Kuemerle、Charlie Salts、Josh Smeaton)