Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot load obfuscated assembly

I'm working for the first time with dotfuscator. My project is written in C# and .NET 3.5, it has a main program and some plugins; this is the slice of code that loads the plugins:

// Load the file
Assembly asm = Assembly.LoadFile( pluginPath );

// Instantiate the types I need
foreach( Type type in asm.GetTypes() )
{
    ...
}

Now the problem is: if i don't obfuscate everything is fine but when i use dotfuscator asm.GetTypes() throw a ReflectionTypeLoadException which says

The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I googled for hours with no result. Thanks in advance.

EDIT: After some researches and debugging I think it's a problem in the manifest, because the reflection can't see (or loads) the types inside the assembly. I opened the obfuscated assembly with Reflector but everything seems fine.

like image 554
Fabrizio Avatar asked Jun 16 '26 10:06

Fabrizio


2 Answers

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.

like image 99
Joe Kuemerle Avatar answered Jun 19 '26 06:06

Joe Kuemerle


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.

like image 36
Charlie Salts Avatar answered Jun 19 '26 04:06

Charlie Salts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!