pamidur / aspect-injector

AOP framework for .NET (c#, vb, etc)
Apache License 2.0
739 stars 110 forks source link

Support `<DebugType>` `Embedded` #175

Open JasonBock opened 2 years ago

JasonBock commented 2 years ago

Note: I did this using different permutations of .NET 5 and .NET 6 target frameworks along with the 2.5.0, 2.6.0, and 2.6.1 versions of AspectInjector, and I believe they all have the same behavior.

Here's the setup. First, make a class library that references AspectInjector (call it AspectInjectorInvestigation). Make sure this setting is in the .csproj file:

<DebugType>Embedded</DebugType>

Add the LogCallAttribute from the readme file, just so you have an aspect in the library.

Next, make another class library called AspectInjectorInvestigation.Usage that references AspectInjectorInvestigation. Put one class in it that does something like this:

public sealed class LogCallUsage
{
  [LogCall]
  public void DoIt() { }
}

Finally, make a test class library called AspectInjectorInvestigation.Usage.Tests (I just used the xUnit template in VS to get it set up). This will reference AspectInjectorInvestigation.Usage. Add a test like this:

[Fact]
public static void LogCall()
{
  var usage = new LogCallUsage();
  usage.DoIt();
}

Make sure you're building in Debug mode, and put a breakpoint on the code in LogEnter() method in LogCallAttribute.

What should happen when you run the test in the debugger is that the breakpoint isn't hit. If I remove the <DebugMode> setting, then the breakpoint is hit.

Also, I've noticed that with the <DebugMode> setting, code coverage isn't done for that class library. If it's removed, code coverage works.

This isn't a showstopper, because the aspect injection works. We only noticed it when we added code coverage metrics in our CI/CD process. We decided to remove that <DebugMode> setting. We weren't sure why it was there in the first place (it was code we inherited :) ), and we don't put that setting into our projects by default. Just wanted to make you aware of this.

pamidur commented 2 years ago

Thank you @JasonBock . it is indeed interesting case. AspectInjector only works with Portable Mode so if there is embedded pdb it will modify the code but won't modify the debug Symbols.

I'll rename this issue to track this feature.

JasonBock commented 2 years ago

That makes sense. If that debug mode isn't supported and that's documented, that works (and again, we usually don't set that mode anyway, so removing it was fine by us). But I get why you want to track this to see if it is something you can potentially support in the future.

mlapaglia commented 1 month ago

setting <DebugType>Embedded</DebugType> allows visual studio to set breakpoints in a referenced nuget package's source code while debugging. Just ran across this issue, is there any support for this or workarounds?