title: How to provide method body for extern method with Mono.Cecil
body: <p>I'm using the MS C# compiler to compile methods like this:</p>
  
  <pre><code>[Placeholder] public extern void Method();
  </code></pre>
  
  <p>The compiled method has <code>RVA = 0</code> (Relative Virtual Address).</p>
  
  <p>Then, with Mono.Cecil 0.9.3, I want to fill up a method body for it.</p>
  
  <p>I do it like this:</p>
  
  <pre><code>methodDefinition.Body = new MethodBody(methodDefinition);
  // emit code...
  </code></pre>
  
  <p>When trying to save the assembly, though, I get an error:</p>
  
  <pre><code> 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&amp; symbols)
      at Mono.Cecil.Cil.CodeWriter.WriteUnresolvedMethodBody(MethodDefinition method)
      at Mono.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition method)
  </code></pre>
  
  <p>How can I make it work?</p>