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?
-
Please don't put "C#" in your title just to indicate that it's a C# question. That's what the tags are for. – John Saunders Jun 16 '11 at 19:45
-
Where did you put it after compiling it? – Simon Wilson Jun 16 '11 at 19:46
-
1He should have said "nudge nudge wink wink" along with his question -- he's obviously trying to decompile something for which he does not have the source. – Ed Bayiates Jun 16 '11 at 19:48
4 Answers
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.

- 1,023,142
- 271
- 3,287
- 2,928
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.

- 47,437
- 25
- 129
- 188
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?
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.

- 70,210
- 21
- 112
- 164