Questions tagged [mono.cecil]

Mono.Cecil is a library to generate and inspect programs and libraries in the ECMA CIL form.

Mono.Cecil is a cross platform library, working equally well on .net and Mono, used to analyze, modify and write .net assemblies.

It is used in a variety of open source projects and commercial products.

Links

390 questions
5
votes
1 answer

What's the relationship between Mono Cecil and NRefactory and how to compare them to Roslyn?

I understand that Microsoft's Compiler as a Service or Roslyn project was inspired by Mono Cecil. But what's the relationship between Mono Cecil and NRefactory? Does one use the other? Or are they alternative technologies that do the same thing? It…
Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
5
votes
1 answer

What is wrong with this CIL?

I'm generating some code via Cecil. The code generates without error, but when I try to load the assembly I get: An unhandled exception of type 'System.InvalidProgramException' occurred in DataSerializersTest.exe Additional information: Common…
me--
  • 1,978
  • 1
  • 22
  • 42
5
votes
1 answer

Is there a generic CIL code to convert any type instance to string?

Is it possible to write generic CIL instructions which will convert instances of any type (both value and reference) to System.String? In particular, I'm interested in Mono.Cecil code which will inject those instructions into a method. Analyzing a…
5
votes
1 answer

How can I use Cecil to find the type passed to a generic method?

I'm trying to use Cecil to find instances of calls to a generic method using an interface for a convention test. I'm having trouble identifying the generic type from the MethodReference. I've set up a basic test: private interface…
Rebecca Scott
  • 2,421
  • 2
  • 25
  • 39
5
votes
1 answer

How to save a changed assembly using Mono.Cecil?

I have a version of Mono.Cecil which does not have the AssemblyFactory class. Probably it is the 0.9 version of the Cecil class. Is there a way out?
Sunil Jadhav
  • 81
  • 10
5
votes
1 answer

Emitting function with optional parameter

I have the following C# code: public static double f(double x1, double x2 = 1) { return x1 * x2; } And here it's IL code (ILSpy): .method public hidebysig static float64 f ( float64 x1, [opt] float64 x2 ) cil managed…
Ivan Kochurkin
  • 4,413
  • 8
  • 45
  • 80
5
votes
1 answer

Mono.Cecil Exception thrown when analyzing .NET 4.5 version of System.Xml DLL, why?

I'm using Mono.Cecil 0.9.5.3, and after installing VS2012 RC (which causes the .NET 4.0 System.XML.DLL to be replaced with its .NET 4.5 counterpart), I get an System.ArugmentException in some code that iterates each methods' custom attributes. It…
Omer Raviv
  • 11,409
  • 5
  • 43
  • 82
4
votes
1 answer

How can I use Mono.Cecil to check if .pdb and .dll file match?

We're using Mono.Cecil in our project. Does it have any functionality that allows me to check whether a specific PDB and DLL match? Thanks!
VitalyB
  • 12,397
  • 9
  • 72
  • 94
4
votes
3 answers

What is the most interesting and promising approach to implement a compiler in C#?

I am just in the beginning of my graduation project that is supposed to last for 6 months. The goal of the project is to implement a .Net-compiler for one scripting language. I had the Compiler Construction as a subject in my curriculum and am…
Alexander Galkin
  • 12,086
  • 12
  • 63
  • 115
4
votes
1 answer

Mono.Cecil: Operation could destabilize at runtime

I followed the hints here, I even put the following lines in: var MSILWorker = prop.SetMethod.Body.GetILProcessor(); MSILWorker.Body.InitLocals = true; I have two properties in two classes: [NotifyProperty] public int Number { get; set; } and …
TDaver
  • 7,164
  • 5
  • 47
  • 94
4
votes
3 answers

Mono.Cecil, Missing compiler required member 'System.Runtime.CompilerServices.ExtensionAttribute..ctor'

I downloaded the latest Mono.Cecil and now whenever I start up my project it gives me that error. It goes away if I remove and add mono.cecil. But that is a pain to do every time I open my project.
Will
  • 10,013
  • 9
  • 45
  • 77
4
votes
2 answers

How to implement IsAssignableFrom with Mono.Cecil

I have a type Type that I wish to search an assembly for derived types. I'm trying to use Mono.Cecil to prescan the assembly for performance reasons. Scanning and loading all assemblies is taking too long and its been suggested that cecil is much…
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
4
votes
1 answer

Mono.Cecil: create local variable and change return statement

I'm trying to rewrite the get method of an property from: get { return dataString; } to: get { string temp = dataString; PropertyLogging.Get("DataString", ref temp); return temp; } So far I've tried differnt things: //the…
Markus
  • 123
  • 2
  • 11
4
votes
1 answer

How can I identify the arguments that will be passed to a particular IL method call in Mono.Cecil

I am using Mono.Cecil to do some analysis and rewriting on an assembly. In some cases this is pretty easy: you can just look right before the call to see where the arguments are loaded: // Math.Pow(2, 4) IL_0001: ldc.r8 00 00 00 00 00 00 00 40…
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
4
votes
1 answer

Mono.Cecil auto-implemented property accessing backing field

I am using Mono.Cecil to inject some IL code in auto-implemented property setter. The problem is, i can get reference to it from TypeDefinition.Fields object but when i inject ldfld instruction (after ldarg.0 instruction ofc) with that reference it…