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 instruction labels resolving

I am using Mono.Cecil to inject some instructions in property setter and i have weird bug when injecting Brfalse_s instruction. Here is code, it's short and simple. private void InjectNullProtection(PropertyDefinition property) { …
3
votes
2 answers

Writing Over Assemblies Using Mono.Cecil

I am trying to write over an assembly that is currently loaded into the AppDomain using Mono.Cecil and I keep getting an IO error saying the file is in use. What I'm doing at the moment is creating an assembly using AssemblyDefinitiion.Create()…
The Pax Bisonica
  • 2,154
  • 2
  • 26
  • 45
3
votes
0 answers

Invalid IL code when using callvirt with Mono.Cecil - C#

I'm trying to execute this code: Assembly.LoadFrom(Path.Combine(Application.dataPath, "Mods/VapidModLoader.dll")).GetType("Vapid.ModLoader.ModLoaderActivator").GetMethod("Activate").Invoke(null, null); In my attempt of doing so, I wrote this using…
Vapid
  • 701
  • 7
  • 27
3
votes
1 answer

C# add Code to an Method at Runtime or with Mono.Cecil

for my Logging Lib i´m planning to develop a few Features. The first one will Log the called Method and it´s Parameters. For Example public void DoSomething(int value) { try { // Exception is thrown } catch(Exception ex) …
Alex
  • 600
  • 1
  • 7
  • 20
3
votes
1 answer

Separating pre- and post- base or chained constructor call instructions for a C# constructor

For a project to add mixins to C# using code weaving, I am cloning code from a source mixin type's parameterless instance constructor to constructors in a target type. For the purposes of this, I divide a constructor into three conceptual parts, and…
rileywhite
  • 365
  • 2
  • 12
3
votes
1 answer

Read/Get TypeRef table from assembly metadata

This is a follow-up question to THIS one: To analyze an assembly (or the types it ueses) I would like to read the TypeRef table of such assembly. I got the hint to use Mono.Cecil to do this, but I only found examples reading TypeDef information.…
Christoph Fink
  • 22,727
  • 9
  • 68
  • 113
3
votes
1 answer

DynamicMethod in Cecil

Is there anything similar to Reflection.Emit.DynamicMethod in Cecil? Thanks. DynamicMethod Edit: What about for the following things? EmitCall (e.g. IL.EmitCall(OpCodes.Callvirt, GetBuildKey, null); IL.Emit(OpCodes.Unbox_Any,…
Michael Sync
  • 4,834
  • 10
  • 40
  • 58
3
votes
1 answer

Replace Attribute constructor arguments with mono.cecil or postsharp

I have an example method definition: [FooAttribute("One","time")] public void Bar(){} Is it possible through one of the above techniques to change, for example, the argument "one" to "two" ?
Sergiu Todirascu
  • 1,367
  • 15
  • 23
3
votes
0 answers

Deriving a Reference Assemblies path from a TargetFrameworkAttribute

I'm processing assemblies with Mono.Cecil in a standalone tool. The tool is intended to be framework-neutral (i.e. will load in any .NET 4[.x[.x]] environment] and not have a dependency on e.g. the .NET SDK. Say I have an assembly containing the…
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
3
votes
1 answer

Method import using Mono.Cecil

Help me please with method import. I want to weave assembly and inject method call reference from base class defined in the other assembly (in fact it's the assembly where weaving code is defined). private void InsertCallSetReference() { //Get…
kreig
  • 990
  • 11
  • 18
3
votes
3 answers

Detect whether the assembly was built for .NET Compact Framework

Having a .NET assembly, how can I detect whether it was built for .NET CF or a full framework?
Andrey Shchekin
  • 21,101
  • 19
  • 94
  • 162
3
votes
1 answer

Using Mono.Cecil with .NET CompactFramework on Windows Mobile devices

I am trying to port Mono.Cecil to work with the .NET CompactFramework 3.5 on Windows Mobile 6 devices. Firstly, I had to make a couple of odd tweaks to the source code of Mono.Cecil (from its GitHub page, commit: ec2a54fb00). It's a bit surprising…
ghd
  • 258
  • 1
  • 3
  • 14
3
votes
2 answers

Building a (non-PCL) Monotouch or .net dll from a single .csproj

Code reuse across .NET and Monotouch has been addressed in many ways, but most techniques involve parallel sets of projects/solutions. I'd like this question to clarify whether it is possible to build, using a single csproj file, either a .NET or a…
bright
  • 4,700
  • 1
  • 34
  • 59
3
votes
1 answer

adding a new constructor to "existing" type with mono.cecil

I am trying to add new overloaded constructor to an existing type. I tried to do it with emit namespace, however created type doesnt inherit the base class and all other methods. And after reading some articles, i decided its not possible with .net…
user1934537
  • 49
  • 1
  • 5
3
votes
1 answer

ILSpy "Failed to resolve assembly" in AstBuilder

I want to decompile a method in my assembly, which references e.g. 'Microsoft.SharePoint.dll', but I have no SharePoint installed on the machine. If I use the following code I get an Mono.Cecil.AssemblyResolutionException 'failed to resolve…
Torsten
  • 226
  • 3
  • 8