Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

obfuscation is what you want to search for.

There is a free one (that is limited) in visual studio called Dotfuscator.

Uses fancy methods to rename your code and alter flowpaths to obscure it.

Consider using an obfuscator.

If you are developing desktop applications converting your code to Dll will not hide the it( there are many tools to decompile the dll or exe files).

but if you are using Asp.Net, then you can compile your site to Dll, and the code will not be visible in the aspx pages, it will be compiled to Dll, you can do that by right click on your project on solution explorer, then choose Publish website

But in all cases .Net Exe files and DLL will be easy to decompile and extract the source code again, unless you use tool to obfuscator your code.

are you talking about ASP.NET ? Websites ? hide the aspx and cs source codes?

if yes, please see my question :

pre compile website in Setup & Deployment

:)

If you mean, the end-user can view your source code by decompiling it, you can protect yourself using an obfuscator.

There is standard obfuscator build in into Visual Studio. In the menu choose Tools / Dotfuscator community edition.

I think my reply to a similar question about JavaScript obfuscation applies here as well: in short, why bother? Your question has already been answered here ("use an obfuscator"), but I thought it wouldn't hurt to find out what your motivations are. Generally, code that you give to people is "in the hands of the enemy" -- if somebody wants to use it/figure out how it works badly enough, they will.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top