"The module was expected to contain an assembly manifest."

user2826133 picture user2826133 · Jan 17, 2014 · Viewed 12.7k times · Source

I have a C# .NET DLL that I'm trying to patch. I chose .NET Reflector with the Reflexil plugin for the job (along with de4dot for deobfuscation). Reflector was able to very successfully show me the C# I wanted to see and I was able to patch the CIL assembly with Reflexil. When I tried to save the DLL as a new binary, Reflexil gave me a Signed Assembly dialog box, I chose to Remove Strong Name.

When I try to run the code that loads the assembly I get the error:

System.BadImageFormatException: Could not load file or assembly 'MyAssembly, Version=1.0, Culture=neutral, PublicKeyToken=somehash' or one of its dependencies. The module was expected to contain an assembly manifest.

How do I solve this problem?

Additionally, if I use peverify.exe on the patched DLL I get an error: File not found or has bad headers. This is leading me to believe there is something wrong with Reflexil's patching process?

Answer

Cosmin Vană picture Cosmin Vană · Jan 17, 2014

Normally, you can add an assembly manifest file to your project (right click on your project, add new file and chose application manifest file). This applies to the dll that will be generated from your assembly. After you add a manifest file, when you right click the project and chose properties, on the Application tab you will see that a manifest file is selected in a dropdown to the bottom.

Probably that dll was also created from a project (class library) which had an application manifest file. I don't think you will be able to alter that dll to add a manifest file anyway.