CIL (Common Intermediate Language) is a low-level language used by Microsoft .NET Framework and Mono.
Questions tagged [il]
477 questions
27
votes
6 answers
Creating method dynamically, and executing it
Background:
I want to define few static methods in C# , and generate IL code as byte array, from one of these methods, selected at runtime (on client), and send the byte array over network to another machine (server) where it should be executed…

Nawaz
- 353,942
- 115
- 666
- 851
26
votes
2 answers
Is there a race condition in this common pattern used to prevent NullReferenceException?
I asked this question and got this interesting (and a little disconcerting) answer.
Daniel states in his answer (unless I'm reading it incorrectly) that the ECMA-335 CLI specification could allow a compiler to generate code that throws a…

qxn
- 17,162
- 3
- 49
- 72
25
votes
2 answers
Why does MSFT C# compile a Fixed "array to pointer decay" and "address of first element" differently?
The .NET c# compiler (.NET 4.0) compiles the fixed statement in a rather peculiar way.
Here's a short but complete program to show you what I am talking about.
using System;
public static class FixedExample {
public static void Main() {
…

Michael Graczyk
- 4,905
- 2
- 22
- 34
24
votes
4 answers
How to Learn IL on the CLR
Since these IL codes what I see more, I like to learn how to interpret them correctly.
I couldn't find a documentation like C# Compiler or any other so I think I can pretty much take care of the rest after I learn this common ones:
Below are some…

Tarik
- 79,711
- 83
- 236
- 349
20
votes
3 answers
C# generated IL for ++ operator - when and why prefix/postfix notation is faster
Since this question is about the increment operator and speed differences with prefix/postfix notation, I will describe the question very carefully lest Eric Lippert discover it and flame me!
(further info and more detail on why I am asking can be…

Simon Hewitt
- 1,391
- 9
- 24
19
votes
3 answers
Why is the 'br.s' IL opcode used in this case?
For educational purposes I'm learning a bit of IL (mainly because I was curious what happens to '%' under the hood (which turns out to be rem) and started digressing...).
I wrote a method, just returning true to break things down a bit and was…

Apeiron
- 602
- 6
- 17
19
votes
2 answers
Why c# compiler in some cases emits newobj/stobj rather than 'call instance .ctor' for struct initialization
here some test program in c#:
using System;
struct Foo {
int x;
public Foo(int x) {
this.x = x;
}
public override string ToString() {
return x.ToString();
}
}
class Program {
static void PrintFoo(ref Foo…

andrey.ko
- 852
- 1
- 7
- 17
19
votes
4 answers
Compiler generated sealed class for delegate keyword contains virtual methods
When delegate keyword is used in C#, the C# compiler automatically generates a class derived from System.MulticastDelegate class.
This compiler generated class contains 3 methods as well: Invoke, BeginInvoke and EndInvoke.
All these three methods…

Amit Mittal
- 2,646
- 16
- 24
18
votes
1 answer
Execute .NET IL code in C#
Is there any way to execute an array of IL codes in C# like shell codes in C/C++?
I want to create a method, convert it to IL code, obfuscate it and store in an array of bytes and finally want to execute it decrypt the array content and execute IL…

Kamran
- 387
- 1
- 3
- 19
17
votes
5 answers
Why is the .ctor() created when I compile C# code into IL?
With this simple C# code, I run csc hello.cs; ildasm /out=hello.txt hello.exe.
class Hello
{
public static void Main()
{
System.Console.WriteLine("hi");
}
}
This is the IL code from ildasm.
.class private auto ansi…

prosseek
- 182,215
- 215
- 566
- 871
17
votes
6 answers
Convert C# code to IL code
How I can get IL code of C# code ? Can I do this with a extern library, or exists internal functions ?
EDIT : I want to show IL code in my application with a MessageBox.

Michaël
- 6,676
- 3
- 36
- 55
17
votes
5 answers
Could not load file or assembly 'AssemblyName PublicKeyToken=null' or one of its dependencies
{"Could not load file or assembly 'AssemblyName, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"AssemblyName,…

Pantelis
- 2,060
- 3
- 25
- 40
17
votes
3 answers
Do I understand this MSIL code correctly?
I have the following code in C#
// test.Program
private static void Main()
{
int x = 5;
int y = 100;
Console.WriteLine(y + ", " + x);
}
And I'm reading the IL code, I've never programmed assembly before so I'm asking if what I each line…

NomenNescio
- 2,899
- 8
- 44
- 82
16
votes
3 answers
Can I force the compiler to optimize a specific method?
Is there an attribute I can use to tell the compiler that a method must always be optimized, even if the global /o+ compiler switch is not set?
The reason I ask is because I'm toying with the idea of dynamically creating a method based on the IL…

Thomas Levesque
- 286,951
- 70
- 623
- 758
14
votes
3 answers
call instead of callvirt in case of the new c# 6 "?" null check
Given the two methods:
static void M1(Person p)
{
if (p != null)
{
var p1 = p.Name;
}
}
static void M2(Person p)
{
var p1 = p?.Name;
}
Why the M1 IL code use callvirt:
IL_0007: …

Dudi Keleti
- 2,946
- 18
- 33