Help
Help

Reputation: 39

Can I open My Dll File

I have a .cs file there is my codes.I compiled it and I got a .dll file. Can I open my .dll file and see my c# codes because I want to compile it again?

Upvotes: 0

Views: 7243

Answers (4)

KeithS
KeithS

Reputation: 71591

Since you're using .NET, yes. .NET assemblies are actually designed to be decompiled easily, so reflection is easier and faster.

You simply need a decompilation tool like .NET Reflector to do the decompilation. Reflector is now a retail product, but there are several freeware alternatives; I use CodeReflect.

However, although a tool like this will show you something close to your original code, first off it won't be exact (conditionally-compiled code won't appear, and certain calls and constructs can be optimized, or look the same in IL as a slightly different construct), and second, it won't allow you to change anything. If you have the .cs file and a copy of Visual Studio (or MSBuild; a command-line tool used by VS), you can recompile your source file into the DLL.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039418

Erm, you said that you compiled it once. This means tat you already have the source code. It looks to me a little aberrant to try to decompile a DLL in order to recompile it assuming you have the source code. This being said the C# compiler spits MSIL code, meaning that you could get this MSIL code back from the compiled assembly using a tool like ildasm.exe for example. Then you could modify the resulting IL and recompile it back into a managed assembly using the ilasm.exe utility.

Of course if the initial assembly was signed with a strong key you will not be able to sign it with this same key if you don't dispose with the private key.

There are some tools such as ILSpy (free) and .NET Reflector (commercial) that allow you to disassemble a managed assembly back into some managed language (C#, VB.NET, ...). Of course during this process you cannot expect to get the exact same source code that was used to compile the assembly initially, especially if it was compiled in Release mode with optimizations turned on as things like local variable names and comments are simply not part of the resulting assembly.

Upvotes: 2

Oded
Oded

Reputation: 499302

You can use a disassembler such as Reflector (or one of the many alternatives) to disassemble the CIL back to C#.

Not sure why you would need it if you have compiled the DLL yourself - surely you have the source code?

Upvotes: 0

Neil Knight
Neil Knight

Reputation: 48587

Use Reflector.Net to view your code and you can use it to disassemble your DLL. Alternatively, if you have the original cs files, then you can rebuild using a C# compiler.

Upvotes: 1

Related Questions