How to convert C# to DLL to hide the source code?

Ali picture Ali · Feb 5, 2009 · Viewed 18.3k times · Source

How can I convert my C# code to DLL file in a way that the user of DLL can’t view my source code?

When I make DLL in the way I always do by making a class library project, importing my classes and compiling it, the source code can still be viewed.

Answer

JaredPar picture JaredPar · Feb 5, 2009

I believe you are looking for an obfuscator. This is a tool that will take a compiled DLL and rewrite the code with the intent of it not being meaningfully decompiled by another user. Visual Studio comes with a free Dotfuscator

Note, this will not actually prevent people from looking at your code. They will instead be looking at a very weird translation of your code. There is no way to prevent people from looking at decompiled versions of your code in C# or any other .Net language for that matter.

This is not something that is unique to C#. It is fact a flaw of every language in existence. It's perfectly possible to decompile C code. The difference though is it's much easier to maintain a lot of the original code structure when decompiling managed languages (.Net and Java for instance) because the metadata maintains the original structure.