Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
19 views

Mono.Cecil weaver wrong branch targets

I'm trying to use Mono.Cecil to weave in some instrumentation code into existing methods - basically just a log before all the sequence points. This is simple, I can iterate over all of the sequence ...
Peter Lenkefi's user avatar
0 votes
0 answers
21 views

Using Mono.Cecil to generate HelloWorld IL targeting .NET 8, error loading System.Private.CoreLib

I am trying to use Mono.Cecil (v 0.11.5) to emit an IL assembly as an .EXE, written in C# 12 on .NET 8. Almost all of the information I can find on using Mono.Cecil is for .NET Framework. If it is ...
SAJ14SAJ's user avatar
  • 1,698
1 vote
1 answer
20 views

Is there a way in Mono.Cecil to determine that a MethodDefinition is actually a C# operator without parsing the name?

I want to avoid parsing the name, like op_Equality. Is there another way to determine if the given MethodDefinition is actually an operator?
mark's user avatar
  • 61.8k
1 vote
0 answers
16 views

Matching Mono.Cecil.MethodDefinition with the respective Microsoft.CodeAnalysis.CSharp.Syntax.BaseMethodDeclarationSyntax

Given a Mono.Cecil.MethodDefinition instance and a Microsoft.CodeAnalysis.SyntaxTree instance is there a library that allows to locate inside the syntax tree the matching Microsoft.CodeAnalysis.CSharp....
mark's user avatar
  • 61.8k
0 votes
0 answers
55 views

How do I transform a function delegate to IL code

This question is a follow up on Unhandled exception: System.IO.FileNotFoundException: The file or assembly "System.Private.CoreLib" could not be found in custom generated assmbly. I ...
Aaron Junker-Wildi's user avatar
0 votes
1 answer
119 views

Mono.Cecil in C#: How to call method of super class from another assembly

Assume you have a simple class ClassA in AssemblyA that should be extended using Mono.Cecil to call a method on its super class ClassB that is part of another assembly AssemblyB. In fact, I am trying ...
FeXseven's user avatar
0 votes
0 answers
57 views

MissingMethodException when invoking injected method call to a public method in parent class that is located in different assembly

I have two assemblies called game and core. The game assembly I manipulate with Mono.Cecil: I search for specific classes with specifically marked properties in whose setter I inject a method call to ...
Sebastian Barth's user avatar
0 votes
1 answer
85 views

Injecting method calls using Mono.Cecil draws InvalidProgramException in constructor

I use Mono.Cecil to inject two method calls into a constructor. Somehow the construction always fails with the following error: InvalidProgramException: Invalid IL code in Networking.ServerController:....
Sebastian Barth's user avatar
0 votes
1 answer
62 views

Inject method call to all field setters marked with attribute using Mono.Cecil

I have class with the method: class NetworkObject { protected void LocalNetworkVariableChange(object value) { // Do some stuff } } I also have Mono.Cecil setup so that it injects a method ...
Sebastian Barth's user avatar
1 vote
1 answer
508 views

Failure to resolve assembly with Mono.Cecil from jenkins

In my solution, I am writing a unit test with NUnit that uses Mono.Cecil. The concept is pretty simple: I have three assemblies ASource, ATest, ATestUtils. ASource: Contains a class "MyClass&...
BNB's user avatar
  • 21
0 votes
0 answers
80 views

Insert method call into setter causes Invalid IL code

I mark some properties with a custom attribute. If it is present I want to manipulate their setter to include a method call after setting the value. The called method is implemented in the parent ...
Sebastian Barth's user avatar
1 vote
1 answer
133 views

ILWeaving help - [ValidSystemPath] attribute

Problem I'm using Mono.Cecil to IL Weave string property getters that have my custom [ValidSystemPath] attribute on them. The purpose of the attribute is to ensure the property only ever returns valid ...
Dom's user avatar
  • 53
0 votes
1 answer
254 views

coverlet: Unable to instrument module (ArgumentException)

I faced an issue when some projects from solution (NOT ALL) are not being instrumented (have zero coverage, though have active unit tests). All projects in solution have the same package refs and ...
Siarhei Machel's user avatar
0 votes
1 answer
41 views

Get named values from a Fody CustomAttribute Constructor

Can anyone tell me how to read the property assignments of a CustomAttribute's constructor [Display(Name = "This name and value")] They don't seem to appear in either theattribute....
Peter Morris's user avatar
  • 22.7k
0 votes
1 answer
40 views

1-click application validation failed MonoCecil.dll c#

I have a problem running my 1-click application. It stopped working with an error code "Application validation did not succeed". The problem is related to Mono.Cecil.dll and related ...
dome_engineer's user avatar
0 votes
0 answers
144 views

How to insert IL code call into class type constructor in .Net?

I have an assembly I want to use and test. Yet I can not change its source code as .cs files but I am allowed to change it at runtime (say on app loading). In there I have a class with a public ...
DuckQueen's user avatar
  • 722
1 vote
1 answer
190 views

Mono.Cecil: Getting Method Reference from delegate passed as Generic Parameter

I'm trying to get an understanding of which concrete types are providing the implementations of interfaces in an IOC (dependency injection) container. My implementation works fine when there are no ...
AttentionDeficient's user avatar
0 votes
0 answers
181 views

Getting source location from TypeDefinition with Mono.Cecil

I would like to determine which source file defines a specific type using Mono.Cecil. For methods, I can use the SequencePoint collection (for example, I could grab the first SequencePoint and fetch ...
David Airapetyan's user avatar
0 votes
2 answers
185 views

BaseType.Resolve() yielding null for base types in different assembly

I have a method to get all members of a type using mono.cecil, all the way through the type hierarchy, but I've found that often the following statement returns null: (asmType has type 'TypeDefinition'...
Dave Doknjas's user avatar
  • 6,568
0 votes
1 answer
125 views

Is there a way to make debugger work with modified assembly

I am trying to modify assembly before using it. Main file: using IlGenTestTarget; using Lokad.ILPack; using System.Reflection; using Mono.Cecil; using IlGenTest; Assembly inAssembly = Assembly....
128_bit_guy's user avatar
1 vote
1 answer
126 views

Mono.Cecil Read Assembly on Linux

I need to reference a dotnet runtime assembly with Mono.Cecil on a Linux Machine. This is a 2 part question. Where are the dotnet runtime assemblies stored on Linux (assuming it's an .so file) Does ...
FilipToth's user avatar
  • 147
1 vote
0 answers
1k views

Unity errors when two packages that use Mono Cecil are imported

I have adopted the maintenance of a weaver package for Unity called Malimbe: https://github.com/ExtendRealityLtd/Malimbe Which weaves code to replace tags to remove common boilerplate. Malimbe uses ...
TheStoneFox's user avatar
  • 3,047
1 vote
0 answers
976 views

How to create "System.Runtime.CompilerServices.DefaultInterpolatedStringHandler" type dynamically in C#?

I am trying to create dynamically a type System.Runtime.CompilerServices.DefaultInterpolatedStringHandler in C#. I try: var inst = Activator.CreateInstance(type); type is System.Type = System....
Mike Dev's user avatar
  • 335
1 vote
1 answer
808 views

How to replace method parameter with a variable with Mono.Cecil

I am making a code generation utility for my application, and I have a problem - I don't know how can I replace a method's parameter with a variable created inside it. Example: a) Code before code-...
user avatar
0 votes
0 answers
119 views

Add or modify method body CIL code from bytes

I would like to add methods or modify methods body of an assembly. I have the array of bytes containing the CIL code. Is there a library that does this job ? Mono.Cecil does it, but only from the ...
Arthur Robert's user avatar
1 vote
0 answers
575 views

Cecil fails to resolve assembly

I have a Xamarin Forms app, consuming two in-house NuGet packages, with one depending on the other (lets call them Tools and BaseClasses, with BaseClasses having a dependency on Tools). However, when ...
stealthjong's user avatar
  • 11.1k
1 vote
1 answer
723 views

Injecting a an assembly reference /w Mono Cecil does not work

I'm currently playing with Mono.Cecil to add an assembly reference into an already compiled assembly. I'm using this code to add the reference: this.tracerReference = this.module.ImportReference(...
nein.'s user avatar
  • 2,107
3 votes
1 answer
5k views

Dotpeek ISSUE: unable to decompile the method

Why can't dotpeek decompile the method in the dll?(unable to decompile the method )? // ISSUE: unable to decompile the method. public ChildModel ChildModel { get => this.\u003CChildModel\...
Герман Матисов's user avatar
1 vote
1 answer
178 views

Mono.Cecil AddInterfaceImplementation equivalent?

I am working on Mono.Cecil codegen util, and I want to preform following operation: Loop through types If type contains X attribute: - Add ITestInterface implementation (where ITestInterface has ...
user avatar
1 vote
1 answer
863 views

How can I run assemblies generated by Mono.Cecil on a Windows Machine?

I have been playing around with Mono.Cecil recently, mainly for a compiler that I'm planning on writing. I started by trying out the code in this answer. Here is the code: var myHelloWorldApp = ...
Sweeper's user avatar
  • 257k
1 vote
1 answer
195 views

Add Static Instance Field to Class and Set To Self in Constructor

Using Mono.Cecil I'm trying to patch a class to add a static field "Instance" and set it inside the constructor. It's essentially the equivalent of adding the following: public static Class1 ...
Brandon Woolworth's user avatar
1 vote
2 answers
466 views

Is it possible in Mono.Cecil to determine the actual type of an object on which a method is called?

For example, consider the following C# code: interface IBase { void f(int); } interface IDerived : IBase { /* inherits f from IBase */ } ... void SomeFunction() { IDerived o = ...; o.f(5); } ...
mark's user avatar
  • 61.8k
2 votes
0 answers
386 views

NullableAttribute is declared in another module and needs to be imported - ILRepack

So I'm using ILRepack, which as far as I understand, uses Mono.Cecil behind the scenes, to do ILWeaving. I'm running into a problem in my project, which ends up resulting in the following error as ...
Capsup's user avatar
  • 87
0 votes
1 answer
744 views

Does Mono.Cecil support full PDB format

I need to keep track of source code lines based on which certain instructions are to be injected. Steps I followed are as below: Built my project in debug mode which generated DLLs and corresponding ...
yesha thakrar's user avatar
0 votes
0 answers
127 views

Is there anyway to update IL instructions to use new local variable indexes?

I am trying to inject a method into another method. Problem is the local variables indexes. Example- public void Method1() { var tes = "anything"; } public void ...
asta nigem's user avatar
0 votes
1 answer
100 views

I want to using Cecil to create an Action<,> , but i don`t know how add genericity parameter

I want to add an Action<,> filed On my class create by using Mono.cecill. But i can`t get the type of uncertainty. How do i create it? I wrote it like this, but it's wrong: var ...
Miao's user avatar
  • 13
1 vote
0 answers
2k views

How Can I Get Target Framework Of An Assembly?

I am loading different assemblies using Mono.Cecil and I would like to know if the assembly is targeting .NET Framework or .NET Core. What I have tried is retrieving the custom attribute ...
youssef jirari's user avatar
0 votes
1 answer
202 views

How can i mock a return type of a factory method of a 3rd party library?

I am working on a tool that loads assemblies using Mono.Cecil. I have the following Factory that returns an object named binary and depends on interface responsible for loading assemblies with ...
youssef jirari's user avatar
1 vote
0 answers
88 views

Why PublicKeyToken changed?

Attempting to make bindingRedirect from Mono.Cecil v0.9.5 to 0.10.0, I've found, since v0.10.0 a PublicKeyToken changed. v0.9.5, 0.9.6 (& probably some other <0.10.0) have PublicKeyToken - ...
user1234567's user avatar
  • 4,271
0 votes
0 answers
118 views

Assembly rename and Xaml resources

I want to be able to load a dll into one app domain multiple times and it should be possible to make code changes between every load. Currently I use Mono.Cecil to rename the namespace on types to ...
Kristoffer Tungland's user avatar
4 votes
1 answer
812 views

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 ...
Just a learner's user avatar
0 votes
1 answer
262 views

CIL instruction "isinst [System.Runtime]System.Int32" for value 0 (int32) - what will return?

I have a simple C# function public bool Isinst_intSimple(object value) { return value is int; } As expected Isinst_intSimple(0) returns true After decompiling, the function looks like: IL_0000: ...
Mike Dev's user avatar
  • 335
0 votes
1 answer
112 views

How to return Task.FromResult<bool>(true) using mono cecil?

I need to use mono cecil to implement the following logic. public Task<bool> MyTask() { return Task.FromResult<bool>(true); } I only know how to invoke non-generic method, since there ...
Just a learner's user avatar
1 vote
1 answer
284 views

Unity script won't update after first successful weaving with Mono.Cecil

I'm using Mono.Cecil to modify assemblies post compilation within Unity (I'm using this implementation of Mono.Cecil). For some reason, if I add a field to a type in an assembly, and the type of the ...
Jake's user avatar
  • 73
1 vote
0 answers
25 views

What methods does the OtherMethods property refer to on properties and events in the Mono.Cecil object model?

Namely: Mono.Cecil.PropertyDefinition.OtherMethods Mono.Cecil.EventDefinition.OtherMethods These are neither Get/Set not Add/Remove methods. So what are they?
mark's user avatar
  • 61.8k
3 votes
2 answers
823 views

How to match type symbol names as returned by Roslyn semantic model to those returned by Mono.Cecil?

I have the following piece of code: var paramDeclType = m_semanticModel.GetTypeInfo(paramDecl.Type).Type; Where paramDeclType.ToString() returns System.Collections.Generic.Dictionary<string, ...
mark's user avatar
  • 61.8k
1 vote
1 answer
788 views

How to resolve references of a .NET assembly from a .Net Core 3.1 code using Mono.Cecil?

My tool is written in .Net Core 3.1. It uses Mono.Cecil to analyze the given assembly, which targets .NET 4.7.2 Given an AssemblyDefinition object and one of its assembly references, I wish to get the ...
mark's user avatar
  • 61.8k
0 votes
0 answers
198 views

Detect which async overload is called inside a C# method using reflection

Using reflection, I need to determine which overloads a particular async method is calling. In this case, I need to inspect the DoSomething() method to determine which method calls to MyMethod() it's ...
Jon Halliday's user avatar
1 vote
1 answer
713 views

I want to use Mono. Cecil to create a delegate, but I don't know how to get its constructor

I want to be able to generate il for the code InjectBake.AddConstruction(typeof(Tests.TestConst), new Func<object[], IServiceProvider, object>[] { Test1, Test2 }); I saw this code in ...
Miao's user avatar
  • 13
1 vote
1 answer
753 views

C# Mono.Cecil injected IL Code does not get executed

I want to make a little sample code with Mono.Cecil The goal is to manipulate the IL. The method X does print something on the console. To test the manipulation of the IL code i remove all ...
MjeOsX's user avatar
  • 405

1
2 3 4 5
8