Click here to Skip to main content
13,767,570 members
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 21 Sep 2012
Licenced CPOL


, 21 Sep 2012
Rate this:
Please Sign up or sign in to vote.
A program to compile C# code into MSIL code.

Download source 

Download executable 



A while back, I was trying to improve the efficiency of a program and in doing so, I needed to view the MSIL of the assembly I was working on. It soon became very tedious to have to build my program then switch over to Microsoft Ildasm to have to keep looking at my disassembly. I tried looking on the Internet for something that would let me view my C# code and my IL code together, but I found no such thing. Hence IlPad was born. 

What it does 

IlPad opens up with 4 panels. The top panel is a text box where you can enter C# code. It can be a whole program or just part of a class. To the right is another panel which shows which assemblies you currently have referenced. There is a button that opens up where you can reference even more assemblies if you need to. Below the C# editor is a button. Clicking on this button will compile your snippet and the resulting IL code is shown in another text box below that. If there are any errors in your C# code, the errors will be outputted to a list box at the bottom of IlPad. The list box will give you a description of the error along with a line number where the error occurred. IlPad is that easy to use! 

In addition to all that, I have included two sample snippet codes. By clicking on either of the two snippet code buttons at the top of the window, the text box will automatically fill in a code snippet. Both of these snippets run without having to reference any additional assemblies. 

How IlPad works 

IlPad works by taking advantage of the CSharpCodeProvider class. This class will let you dynamically compile C# code into either an in-memory assembly or an assembly outputted to a file. Here is a snippet of code from IlPad that does the compilation:

var options = new Dictionary<string, string> {{"CompilerVersion", "v4.0"}};
var provider = new CSharpCodeProvider(options);
var parms = new CompilerParameters
        CompilerOptions = @"/lib:C:\Windows\assembly\GAC /target:library",
        GenerateExecutable = true,
        GenerateInMemory = false
foreach (string item in lbReferences.Items)
    parms.ReferencedAssemblies.Add(item + ".dll");
string outFile = Path.GetTempFileName();
string ilOutFile = Path.GetTempFileName();
string ildasm = Path.GetTempFileName() + ".exe";
parms.OutputAssembly = outFile;
CompilerResults res = provider.CompileAssemblyFromSource(parms, txtInputProgram.Text);

IlPad targets .NET 4.0. IlPad could be made to run in .NET 3.5, if needed. IlPad creates a temporary file to store the compiled assembly. Once the assembly is successfully created, IlPad runs IlDasm. IlDasm is a disassembler created by Microsoft that disassembles .NET assemblies into MSIL code.  

Things yet to do 

When I get more time, thee are some things I'd like to do to improve IlPad. Here is a short to do list:

  • Add VB.NET support
  • Improve the "Add a Reference" dialog
  • Syntax highlighting (both source code and IL code) 
  • Automatic code formatting
  • Possibly add F# support 
  • Create a snippet library and add more snippets
  • Ability to create and store your own snippets in the snippet library 
Of course, if anyone has any suggestions or things they'd like to see added, I'd love to hear any ideas! 


1.0 - Initial Release


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionFour Star! Pin
kabdolla25-Sep-12 6:04
professionalkabdolla25-Sep-12 6:04 
GeneralMy vote of 5 Pin
Gunjan Bhasin22-Sep-12 9:23
memberGunjan Bhasin22-Sep-12 9:23 
GeneralMy vote of 2 Pin
Paul Tait21-Sep-12 21:19
memberPaul Tait21-Sep-12 21:19 
GeneralRe: My vote of 2 Pin
icemanind22-Sep-12 4:18
membericemanind22-Sep-12 4:18 
GeneralRe: My vote of 2 Pin
Winfried Lötzsch22-Sep-12 4:58
memberWinfried Lötzsch22-Sep-12 4:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05-2016 | 2.8.181116.1 | Last Updated 22 Sep 2012
Article Copyright 2012 by icemanind
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid