4

I've made a very simple aspect, and found a problem when debugging it (see code). I set a breakpoint on the method exit, and it hits inside "entry" method actually. PostSharp 1.5, Visual Studio 2008 SP1
Is this a known bug, are there any workarounds?

class Program
{
    [MyAspect]
    static void Main(string[] args)
    {
        Console.WriteLine("body");
    } // setting breakpoint here
}

[Serializable]
class MyAspect : OnMethodBoundaryAspect
{
    public override void OnEntry(MethodExecutionEventArgs eventArgs)
    { // hits here actually! (debug mode)
        Console.WriteLine("entry"); // hits here actually! (release mode)
    }

    public override void OnExit(MethodExecutionEventArgs eventArgs)
    {
        Console.WriteLine("exit");
    }
}
skevar7
  • 995
  • 1
  • 10
  • 21

4 Answers4

3

Usually this happens when the debugging symbols are out of date or don't match the executable being run.

I use PostSharp and haven't seen anything like this before... Have you tried a rebuild? Or deleting your output folder and then building?

Edit:

So I ran your sample. If you move the MyAspect implementation to another file, when you start debugging the code, the breakpoint becomes unavailable with the message: "The breakpoint will not currently be hit. No executable is associated with this line..."

Without the aspect applied, it doesn't happen. So yes, looks like something in post compile step does cause the issue.

I'll leave this answer here as clarification of the question. If you think its not useful, I can delete it too...

Edit 2: As for workaround: Set the breakpoint to the previous line (not on the closing brace), and then step over the last line of code in the method...

Nader Shirazie
  • 10,736
  • 2
  • 37
  • 43
  • Rebuild/cleanup doesn't change anything. Have you tried executing my sample? – skevar7 Sep 08 '09 at 05:39
  • This seems to be a .pdb problem. PostSharp modifies only the assembly but not the debug symbol file. – boj Sep 27 '10 at 14:33
0

This may be a bug of PostSharp. You can report it to http://www.postsharp.org/tracker.

Gael Fraiteur
  • 6,759
  • 2
  • 24
  • 31
0

While searching for solutions for this issue, I stumbled upon this thread. I had the same problem and found out something about it.

It SEEMS (i do not really KNOW it) that it has to do with the order things happen in the build process. my idea is the following of what happens when build/rebuild (cleanup doesn't matter in my case):

  • build assemblies
  • create .pdb for them
  • build again, apply postsharp code
  • .pdb's are not created again (i guess!!)

which would mean: the .pdb does not match the code being debugged. why do i think this way? well, if i disable postsharp on the assembly, everything works fine. when it is enable, simple code like "string str = "test"; are, as Nader Shirazie mentioned "not associated with executable code". which i cannot agree.

I am still searching for a "real" solution. my current workaround, disabling postsharp for the assembly, is not really satisfying, as I want to debug the aspects, of course, too. maybee it's just a simple setting. i cannot imagine a tool like postsharp, which shall improve productivity and quality, make debugging fail... anyone?

I can be wrong, but that's how it looks like in my case.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
schwebbe
  • 90
  • 1
  • 13
0

This seems to be because PostSharp "injects" code into your methods when you compile the project so the break point lines and all exceptions line numbers are all off by 'X' amount of lines. You can look at the decompiled .dll and see all of the code that PostSharp has injected into your code base that causes the .pdb files to be out of sync with the .dll

Jason Roell
  • 6,679
  • 4
  • 21
  • 28
  • Normally PostSharp also modifies the .pdb file to match the new .dll. The out-of-sync issue would be caused by a bug or some incompatibility (e.g. changes in .pdb format). – AlexD Jan 23 '15 at 20:03