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
3
votes
1 answer

Mono Cecil - Initializing a local variable

I have the following method: public void DoSomething() { Console.WriteLine(""); } I want to modify this code with Mono Cecil. I want to create an instance of a custom class within the method: public void DoSomething() { MyClass instance = new…
Daniel
  • 920
  • 7
  • 19
3
votes
1 answer

How can I change field value with Mono Cecil?

I have a C# program and it has a class: public class Test { internal const string a = "some value"; private DateTime b = new DateTime(); } How can I use Mono Cecil to change their initial value so that it looks like this: public class…
Just a learner
  • 26,690
  • 50
  • 155
  • 234
3
votes
0 answers

.NET Core 2.2 to 3.1 Azure functions project migration build fails

I have a .NET Core 2.2 Azure functions solution that I'm trying to migrate to .NET ore 3.1. I did the following steps: I changed the project files target framework to netcoreapp3.1 I updated the Nuget packages to the latest stable version I updated…
teost
  • 31
  • 2
3
votes
2 answers

Resolving a TypeReference to a TypeDefinition in Mono.Cecil fails with Assembly Resolution Error

I'm trying to get a Mono.Cecil TypeDefinition from a .NET type and not having any luck. I'm using code like this: var type = typeof(MarkdownMonster.AppConfiguration); var a = AssemblyDefinition.ReadAssembly(type.Assembly.Location); var tr =…
Rick Strahl
  • 17,302
  • 14
  • 89
  • 134
3
votes
1 answer

Mono.Cecil - simple example how to get method body

I have been searching for a newbie question, but can't find a simple example. Can anyone give me a simple example how to get MethodBody into most available string result? Like: using Mono.Cecil; using Mono.Cecil.Cil; namespace my { public class…
T.Todua
  • 53,146
  • 19
  • 236
  • 237
3
votes
1 answer

Mono.Cecil: call base class' method from other assembly

How can I get a MethodReference to a base class' method by name? I've tried type.BaseType.Resolve().Methods; and if I add the dll containing the base class to the assemblyresolver it returns the methods. But if I add a call using…
TDaver
  • 7,164
  • 5
  • 47
  • 94
3
votes
1 answer

Mono.Cecil - Getting TypeReference from System.Type

Is there possible to get TypeReference or TypeDefinition of type assigned to System.Type variable? To be more concrete, I'm trying to get String type from following definition of attribute: Custom(Value=typeof(String))] public string…
tomwesolowski
  • 956
  • 1
  • 11
  • 27
3
votes
3 answers

Run Mono.Cecil in .NET Core

I ran the HelloWorld console app example from a SO anwser compiled with .NET Core 2 and Mono.Cecil 0.10.0-beta7: var myHelloWorldApp = AssemblyDefinition.CreateAssembly( new AssemblyNameDefinition("HelloWorld", new Version(1, 0, 0, 0)),…
MiP
  • 5,846
  • 3
  • 26
  • 41
3
votes
2 answers

How to inject call to System.Object.Equals with Mono.Cecil?

Using Mono.Cecil I want to rewrite the following property: public string FirstName { get { return _FirstName; } set { _FirstName = value; } } to this: public string FirstName { get { return _FirstName; } set { …
Tim Murphy
  • 4,892
  • 4
  • 40
  • 48
3
votes
5 answers

What kind of compiler magic do we need more?

I develop lot view models which are: 1) All have to implement INotifyPropertyChanged to be bindable to UI. 2) Property setters have to raise PropertyChanged on change. 3) PropertyChanged event has to provide proper property name. If you (like me)…
Lex Lavnikov
  • 1,239
  • 9
  • 18
3
votes
1 answer

Adding static constructor with Mono.Cecil causes TypeInitializationException

I am trying to add a static constructor using Mono Cecil to a program like the following: namespace SimpleTarget { class C { public void M() { Console.WriteLine("Hello, World!"); } } } The following…
Zooey
  • 421
  • 1
  • 4
  • 10
3
votes
1 answer

Trying to reference Task.ContinueWith from Mono.Cecil

The problem I'm trying to get this IL instruction using strictly Mono.Cecil. Right now, the only solution I found involves importing every references assembly and their exported types, call MakeGenericInstanceType(), and Module.Import(). Wanted IL…
Greg
  • 131
  • 3
  • 8
3
votes
1 answer

Custom IL Rewriting plugin for msbuild

I want to create a custom msbuild task that applies IL rwriting to my output assembly. At the moment i am already using PostSharp and now try to extend the rewriting capabilities. For some special cases i use Mono.Cecil to rewrite some proxy types…
3
votes
0 answers

How to tell if two TypeReferences refer to the same type?

With System.Reflection, I can compare two Type objects with ==. How can I determine whether two TypeReference objects refer to the same static type in Mono.Cecil? I'd like an approach that works for generic types, generic type definitions, arrays,…
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
3
votes
1 answer

Create an Instruction for Type

Using Mono.Cecil, given this method private Instruction LoadOnStack(MetadataType type, object value) { switch (type) { case MetadataType.String: return _processor.Create(OpCodes.Ldstr, (string) value); case…
swestner
  • 1,881
  • 15
  • 19