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.