cil

MSIL Property Setter - Access to the value field

I have the following setter-method, but the object I put in value isn't put through to the called method: .method public hidebysig specialname instance void set_SeatingCapacity(int32 'value') cil managed { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() .maxstack 3 L_0000: ...

The curiosity of the let_ property method

Every .net developer knows about the concept of properties. A rough 99.99%, it's just a piece of metadata gluing together two methods, a getter, and a setter. Same thing usually goes for events, with their add, remove, and invoke method. The ECMA-335 describes a «Other» kind of method semantic, that would apply to either a property or ...

Manipulate .NET bytecode - JIT regeneration?

Is it possible to manipulate the bytecode of a (signed) .NET program at runtime? E.g. by forcing the JIT to re-evalutate the IL? ...

ILASM for Compact Framework?

I'm working with Linq expression trees (from the db4o/Mainsoft/Mono port) on the Compact Framework. Since System.Reflection.Emit doesn't exist, I can't compile my LambdaExpressions into delegates, which I want to do for performance reasons. I thought maybe I could transform my expression tree into IL and basically provide the missing Em...

Why .NET code compiles to MSIL?

Hi All,First .NET code compiles to MSIL and then JIT convert it to machine dependent code. Can any one tell me what all benifits get because of the 2 step compilation.Thanks ...

Is there a way to see the native code produced by theJITter for given C# / CIL?

In a comment on this answer (which suggests using bit-shift operators over integer multiplication / division, for performance), I queried whether this would actually be faster. In the back of my mind is an idea that at some level, something will be clever enough to work out that >> 1 and / 2 are the same operation. However, I'm now wonde...

How to tell from a CIL instruction whether a field is read or written to?

I am currently using Mono Cecil to extract data from C# projects. Now I need to check whether a field is read or written to in each method. How can tell from the CIL instruction that a field is being read or written to? Cos I doubt there a library in Mono Cecil similar to Assignment in Eclipse's JDT that allows me to extract the left h...

What would you use to build a new compiler for .NET?

I'm working on a new toy language that will be statically compiled to .NET's IL code. Off hand I can think of the following to actually generate the IL, but I'm open to alternatives: Cecil ILASM ...

CIL,CLS,CTS IN .NET

what is the CIL,CTS,CLS in .net and what is the difference among them? ...

CIL ANTLR Grammer?

Is there any .NET CIL (AKA MSIL) ANTLR grammer? Thank you! ...

How do I find all the type dependecies of a given type in any CLR based language assembly?

I am trying to find all the types that a given type is dependent on, including interfaces, abstract classes, enums, structs, etc. I want to load up an assembly, and print out a list of all the types defined within it, and their dependencies. So far I have been able to find all the the external types a CLR assembly depends on using Mono....

Silverlight 3.0 C# - Using Methodbuilder to create a SET method, and adding the MSIL with ILGenerator and Emit.

Hej All I have some code that builds a new TYPE runtime, it sets the GET and SET method using MethodBuilder. (Its an exampel from the web, and thanks to the Guy, that wrote it, i unfortantly lost the ref. to him, but he is in my thoughts) TypeBuilder typeBuilder = module.DefineType("MyClass", TypeAttributes.Public | TypeAttributes.Clas...

.NET and output file extension

Why Visual Studio compiles an application to an executable if it's in the MSIL format? Shouldn't it be like java that compiles the code to a .class file? ...

C#: writing MSIL to add a preprocessor directive

Is it possible in C# to write MSIL code that will add a preprocessor directive to the code, e.g., #warning, if a certain condition is met? Or maybe this can be done with reflection, I don't know. I'm trying to write a custom attribute that, if applied incorrectly to a class's method or property, will generate a compiler warning. Using...

C# compiler doesn’t optimize unnecessary casts

A few days back, while writing an answer for this question here on overflow I got a bit surprised by the C# compiler, who wasn’t doing what I expected it to do. Look at the following to code snippets: First: object[] array = new object[1]; for (int i = 0; i < 100000; i++) { ICollection<object> col = (ICollection<object>)array; ...

Why does calling a DynamicMethod with an instance of my own class cause an exception?

I'm learning CIL by making my own functions at runtime with Reflection.Emit. I'm actually surprised how easy things have been up until now but I've hit something that I can't guess my way through and I can't find anything relative in the docs. I'm trying to create a function that simply prints a very simple class I have defined. If I ch...

How base.ToString() called using callvirt, can lead to a StackOverflow Exception ?

IL offers two statements for calling functions, i.e. call and callvirt. Call is used to call the non-virtual or static functions or any function where compiler doesn't want to do a null check on the reference. callvirt is used to call virtual functions, non-virtual functions are also called, since compiler does a null check on the refer...

Do I need to write my own unmanaged IL library to rewrite IL with the CLR Profiling API?

I've been looking at some of the articles for the CLR Profiling API, and many of those articles talk about calling SetILFunctionBody() to do the actual IL rewriting; however, none of those articles actually explain exactly what you could use to rewrite the actual method IL bytes. Is there an unmanaged library out there that allows me to ...

How do i prevent my code from being stolen?

What happens exactly when I launch a .NET exe? I know that C# is compiled to IL code and I think the generated exe file just a launcher that starts the runtime and passes the IL code to it. But how? And how complex process is it? IL code is embedded in the exe. I think it can be executed from the memory without writing it to the disk wh...

DynamicMethod NullReferenceException

Can anyone tell me what's wrong with my IL code here? IL_0000: nop IL_0001: ldarg.1 IL_0002: isinst MyXmlWriter IL_0007: stloc.0 IL_0008: ldloc.0 IL_0009: ldarg.2 IL_000a: ldind.ref IL_000b: unbox.any TestEnum IL_0010: ldfld Int64 value__/FastSerializer.TestEnum IL_0015: callvirt Void WriteValue(Int...