Preventing ildasm from disassembling your assembly

The MSIL Disassembler (ildasm.exe) is a neat tool that can be used to view the MSIL code of a .Net assembly/dll. Many of you should have used it to peek into assemblies while debugging/troubleshooting.


I use it a lot to check assembly namespaces and stuff while debugging. But when I tried to disassemble one particular module I received the following error "Protected module -- cannot disassemble"


After a little digging around I found that with .NET 2.0 a new attribute has been introduced that can prevent the MSIL Disassembler from disassembling your module. The SuppressIldasmAttribute available in the System.Runtime.CompilerServices namespace can be used to specify that a module should not be disassembled. And here is how you code it. I am just specifying the SuppressIldasmAttribute for my namespace.



If you compile the above code and try to open the assembly using ildasm.exe you will receive the error message "Protected module -- cannot disassemble"

Remember that the attribute only prevents the ildasm.exe from disassembling the module you can still use Reflector to view the decompiled code. Here is the Reflector view of assembly that has used the SupressIldasmAttribute.


Bookmark and Share

Comments (7)

  1. This is probably one of the most dangerous attributes ever concieved.

    I have ben contracted by multiple clients who thought their intectual property was SECURE because of this attribute (some even INSISTED it was)

    Their shock when I was alble to quickly produce their code from the assemblies was significant.

  2. Bijan says:

    Very misleading attribute

  3. fschwiet says:

    Hmm, I’ve had troubles using reflector to view such assemblies as well as ILDASM.  Maybe its the newer version from Red Gate…  Any other tricks I could try?  fschwiet (at) gmail

  4. Sanjeet says:

    Hello Vijay,

    Nice one. Did you find anything else on the topic that can probably prevent .Net Reflector from disassembling?

    I will post a message if I find anything on it.

  5. Dhanish says:

    Open the .dll/.exe in hexeditor… find for "SuppressIldasmAttribute." and replace it by spaces "20"

  6. Avadhoot Kulkarni says:

    The bets way to address IL theft is to obfuscate your library using obfuscation tools before you make your libraries public.

    Check following links for more details

  7. Dhanish says:

    *NO* dotnet assembly is safe 🙂

Skip to main content