cil

can MSIL be converted to Java Native Code ?

Dotnet CLR converts the language code to MSIL. While Java Code be converted to Native Code that is platform independent. Can we convert this MSIL to Native Code ? So the Dotnet will automatically become platform independent. ...

What OpCodes were introduced in CLR 4.0?

Are there any IL opcodes that are new in .NET 4.0 as compared to 3.5, and if so, where can I find a list of them? ...

Calling instance method on a null reference in IL..

Is it correct that a instance method can be called on a null reference in IL..? Is there any example to show this..? ...

Why is it necessary to load every argument onto the stack in CIL method?

Hi, in my application I need to dynamically create a type that contains multiple properties. I am aware that in cases such as this, one has to generate an CIL for both getter and setter methods of a property by using an ILGenerator. More by a trial and error than anything else, I've finally arrived to the following code that generates ...

Why is there an F# Runtime being installed with Visual Studio 2010?

I'm installing Visual Studio 2010 on a new machine and took a list of the default Components installed. Among them, there is 'Visual Studio F# 2.0 Runtime', which seems strange, because as far as I knew, all .NET languages get compiled to MSIL and are then treated equally (this is obviously not right, since there is a F# Runtime). So h...

What does the CLR do on a 'throw'?

As I was working on a project, I thought to myself "Hmmm, it would be really handy to log a message, and then throw an Exception with that same message". Since this would let me keep my "exceptions are for exceptional circumstances" principle, but still make sure we're recording detailed information about what went wrong in the system. ...

Call a method using a MethodInfo instance on the stack using Reflection.Emit

I am using Reflection.Emit to build a mathematical expression parser (e.g. 2+2). A class takes in an infix expression (e.g. 2+2), turns it into a postfix expression (e.g. 2 2 +), and then another class compiles that postfix expression into IL and creates a DynamicMethod. From there, the expression can be evaluated as if it had been creat...

CIL instruction "isinst <valuetype>"

The ECMA Common Language Infrastructure documentation says this about the CIL "isinst class" instruction: Correct CIL ensures that class is a valid typeref or typedef or typespec token indicating a class, and that obj is always either null or an object reference. This implies that a valuetype is not allowed, right? But mscorlib.d...

FSharp.Core not optimized?

Hello, I've recently inspected the performance of a F# app and while digging through the CIL I've found out that FSharp.Core (for .NET v4.0) contains several nop instructions, many unused variables and variables which are only written/read once via sequences of stloc/ldloc instructions. I've investigated the possible causes and I've noti...

.NET TypeBuilder - VerificationException: Operation could destabilize the runtime.

I need to create a type at runtime using the TypeBuilder. This type should implement a specific interface so that it is possible to treat instances of this dynamic type uniformly at the compile time. The interface should return an array of objects filled with values of specific fields in that type. Interface that is supposed to be imp...

MS C# compiler and non-optimized code

Note: I noticed some errors in my posted example - editing to fix it The official C# compiler does some interesting things if you don't enable optimization. For example, a simple if statement: int x; // ... // if (x == 10) // do something becomes something like the following if optimized: ldloc.0 ldc.i4.s 10 ceq bne.un.s do_not_...

How to become an MSIL pro?

I have spent hours on a debugging problem only to have a more experienced guy look at the IL (something like 00400089 mov dword ptr [ebp-8],edx ) and point out the problem. Honestly, this looks like Hebrew to me - I have no idea what the heck it's saying. Where can I learn more about this stuff and impress everyone around me? My goa...

What's the different between ldsfld and ldstr in IL?

I've read some article about String.Empty vs "" and I also do test by my self. Different between them are below. String.Empty L_0001: ldsfld string [mscorlib]System.String::Empty "" L_0001: ldstr "" After I talk with my friends they argue that String.Empty is faster than "" because under the hood (at assembly level) ldstr do more ...

How does F# compile functions that can take multiple different parameter types into IL?

I know virtually nothing about F#. I don’t even know the syntax, so I can’t give examples. It was mentioned in a comment thread that F# can declare functions that can take parameters of multiple possible types, for example a string or an integer. This would be similar to method overloads in C#: public void Method(string str) { /* ... *...

Is there a way to use IronPython objects and functions (compiled into an assembly) from C# code?

IronPython.net documentation says the MSIL in the assembly isn't CLS-compliant, but is there a workaround? ...

Looking for the exact list of possible MethodAttributes.SpecialName.

I am aware of ctor, cctor, property/indexer prefix: get_, set_, event management prefix: add_, remove_. I have seen a raise_ prefix once or twice (do not remember where). Does a definitive list exists at the .Net level (ECMA spec.)? If yes where is it? Is it an "open list" so that any (new) language can define them for its (future) nee...

Run-time Generation Compilation of CLR

Hi, I have a C# application which generates .NET functions at run-time and executes them. To do so, it generates C# in strings and calls the online C# compiler to convert it into CLR to be JIT compiled and executed. For performance reasons, I would like to be able to generate directly CLR (in strings or through an internal representati...

MSIL Memory Leaks

Hi All We are using a custom RuntimeDataBuilder class that dynamically constructs a .NET type in-memory using Reflection.Emit to create simple property getters/setters for the information that we receive from a generic WCF DataService. The service exposes a "DataSet like" structure consisting out of 1..m DataTableDefinitions each conta...

Is C# faster than VB.NET?

You'd think both are the same. But maybe it's the compiler that Microsoft has used, but I've noticed that when compiling two very small programs, identical logic. VB.NET uses more IL instructions. Is it true than that c# must be faster, if only because its compiler is smarter. ...

How is LINQ compiled into the CIL?

For example: var query = from c in db.Cars select c; foreach(Car aCar in query) { Console.WriteLine(aCar.Name); } How would this translate once it is compiled? What happens behind the scenes? ...