Hi,

I'm trying to do some simple bytecode enhancing using Cecil. I want to
replace some stfld and ldfld instructions with method invocations. And
all that works beautifully. But I need to be able to debug the
modified classes. But while writing the assembly something seems to go
wrong with the line numbers.

Even when I don't actually modify the IL and use just a very simple
class:

public class Person {

  private string name;

  public string Name {
    get {
      return name;
    }
    set {
      name = value;
    }
  }

  private static void Main(string[] argv) {
    Person p = new Person();
    p.Name = "test";
    Console.WriteLine(p.Name);
  }

All I do is to load the assembly and symbols and to write it back
without doing anything beforehand, afterwards or in between:

  AssemblyDefinition myLibrary = AssemblyFactory.GetAssembly
(pathToAssembly);
  myLibrary.MainModule.LoadSymbols();
  myLibrary.MainModule.SaveSymbols();
  AssemblyFactory.SaveAssembly(myLibrary, pathToAssembly);

The strange thing is, the line and column information in the sequence
points of the instructions seems to be perfectly fine before invoking
SaveAssembly(). But when I try to set break points using the
'modified' assembly it doesn't work. And when I watch the disassembly
with Ildasm it sems that all the line and column information is messed
up. When I use an even more simple class (without the property, just
the WriteLine instruction) it does work.

What could I be doing wrong?
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to