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
6
votes
3 answers

Replace references to a type/namespace using Mono.Cecil

Background (unnecessary, confusing, only for the curious) I'm using the free version of Unity3D for Mobile and it doesn't allow me to use the System.Net.Sockets namespace on mobile devices. The problem is that I'm using a compiled .dll library…
user837703
6
votes
2 answers

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…
aj.esler
  • 921
  • 1
  • 8
  • 18
6
votes
1 answer

Accessing properties on System.Collections.Generic.List

Using Mono.Cecil I can iterate over the fields on System.Collections.Generic.List (_items, _size, _version, etc.), however if I try to use them I always get the exception Member 'T[] System.Collections.Generic.List`1::_items' is declared in…
JesseBuesking
  • 6,496
  • 4
  • 44
  • 89
6
votes
2 answers

.NET CIL manipulation of evaluation stack

I have this sequence of CIL codes which I injected through the use of Mono.Cecil. However, the modified .NET C# application will not run. Objective: Manually load and pop values from stack to display in Console.WriteLine for (int i = 0; i < 3;…
Ron
  • 67
  • 1
  • 6
6
votes
2 answers

How do I add a custom attribute without a default constructor using mono.cecil

This question is related to this one, but is not a duplicate. Jb posted there that to add a custom attribute, the following snippet would work: ModuleDefinition module = ...; MethodDefinition targetMethod = ...; MethodReference attributeConstructor…
David M
  • 71,481
  • 13
  • 158
  • 186
5
votes
2 answers

ICSharpCode.Decompiler + Mono.Cecil -> How to generate code for a single method?

I'm able to use Mono.Cecil and ICSharpCode.Decompiler to generate the code for a type or an assembly. But if I try to generate the code for a single method I'll get an error "Object reference not set to an instance of an object." Can you guys give…
lpinho
  • 349
  • 2
  • 5
  • 10
5
votes
1 answer

How to create a GenericParameter return type for a MethodReference in Mono.Cecil?

I'm trying to reproduce the following IL using Mono.Cecil: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, !!0, !!0) When I use Mono.Cecil to inspect this IL, I…
Einar
  • 312
  • 1
  • 10
5
votes
1 answer

Adding a TypeDefinition from another Assembly

This one is driving me crazy. AssemblyDefinition asm1 = AssemblyDefinition.ReadAssembly(example); AssemblyDefinition asm2 = AssemblyDefinition.ReadAssembly(example2); asm2.MainModule.Types.Add(asm1.MainModule.Types[0]); Whenever I try to execute…
method
  • 1,369
  • 3
  • 16
  • 29
5
votes
1 answer

Mono.Cecil Module of BaseType is incorrect

I am loading two assemblies using AssembliyDefinition.ReadAssembly In AssemblyA I define ClassA. In AssemblyB I define ClassB : ClassA. When I inspect the TypeDefinition.BaseType of ClassB I get that its Module is AssemblyB. I wouldbe expected that…
ravyoli
  • 698
  • 6
  • 13
5
votes
2 answers

Where can I get Mono.Cecil.Pdb.dll?

I'm trying to write a IL Weaver with Mono.Cecil, and for it to remain debugable in VS2010, I need the PdbReaderProvider class, or some similar implementation of ISymbolProvider. I've downloaded the latest Mono dlls from…
TDaver
  • 7,164
  • 5
  • 47
  • 94
5
votes
2 answers

Mono Cecil add missing assembly

For some reason when I try to load some assembly and analyze it, I'm getting error Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly... I don't really care about why this exception throw, I know where is the missing assembly. There…
nrofis
  • 8,975
  • 14
  • 58
  • 113
5
votes
1 answer

What is the "" type?

I am using Mono.Cecil to read an assembly generated by Regex.CompileToAssembly(). When I iterate through the types, there is one type in the root namespace named . The type has no base type. What is this type? Is this some Mono.Cecil…
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
5
votes
1 answer

Why Mono.Cecil argues for method import while I have done it already?

Here is my code : private void ModifyMethods() { SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(@" using System; namespace ToIL { public class Class1 { public void Write() { …
Mohsen Sarkar
  • 5,910
  • 7
  • 47
  • 86
5
votes
1 answer

Determining if a Mono.Cecil.MethodDefinition is refering to the same function as a given EnvDTE.CodeFunction

Context I've been trying out jbEvain's powerful Mono.Cecil library for just about two weeks now. I've created the following function : /// /// Returns true only if they match. /// private bool…
Kraven
  • 233
  • 2
  • 11
5
votes
4 answers

Get AST from .Net assembly without source code (IL code)

I'd like to analyze .Net assemblies to be language independent from C#, VB.NET or whatever. I know Roslyn and NRefactory but they only seem to work on C# source code level? There is also the "Common Compiler Infrastructure: Code Model and AST API"…
NKnusperer
  • 974
  • 1
  • 11
  • 31
1 2
3
25 26