I'm using the MS C# compiler to compile methods like this:
[Placeholder] public extern void Method();
The compiled method has RVA = 0
(Relative Virtual Address).
Then, with Mono.Cecil 0.9.3, I want to fill up a method body for it.
I do it like this:
methodDefinition.Body = new MethodBody(methodDefinition);
// emit code...
When trying to save the assembly, though, I get an error:
System.NullReferenceException: Object reference not set to an instance of an object.
at Mono.Cecil.Cil.CodeReader.IsInSection(Int32 rva)
at Mono.Cecil.Cil.CodeReader.MoveTo(Int32 rva)
at Mono.Cecil.Cil.CodeReader.PatchRawMethodBody(MethodDefinition method, CodeWriter writer, MethodSymbols& symbols)
at Mono.Cecil.Cil.CodeWriter.WriteUnresolvedMethodBody(MethodDefinition method)
at Mon开发者_StackOverflow社区o.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition method)
How can I make it work?
I'm ashamed to say that the solution was to just upgrade Mono.Cecil to version 0.9.5.
精彩评论