pamidur / aspect-injector

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

Local variables in sync methods are not visible in the VS debugger #217

Open DaemonSharps opened 1 year ago

DaemonSharps commented 1 year ago

Environment:

Describe the bug Local variables are not visible when debugging synchronous methods when using AspectInjector.

To Reproduce I am using example from README

  [Aspect(Scope.Global)]
  [Injection(typeof(AroundTests_Simple))]
  public class AroundTests_Simple : Attribute
  {
          [Advice(Kind.Around, Targets = Target.Method)]
          public object AroundMethod([Argument(Source.Target)] Func<object[], object> target,
              [Argument(Source.Arguments)] object[] arguments)
          {
              return target(arguments);
          }
      }

Use with synchronous test method.

[TestFixture]
    public class TestClass
    {
        [Test]
        [AroundTests_Simple]
        public void Test()
        {
            var test = 1;

            Assert.True(test == 1);
        }
}

And get that exception: image

But with async method it works correctly: image

Additional info: Old issue for async methods https://github.com/pamidur/aspect-injector/issues/71

pamidur commented 1 year ago

It is a side effect of the way around method is implemented. I didn't catch it earlier somehow :) Asyncs have a bit different implementation thought. I'll look into it! Thank for the report

pamidur commented 1 year ago

please see if 2.8.2-pre3 fixes it for you?

DaemonSharps commented 1 year ago

Yes, it`s work! Thank you!!!!

StefH commented 1 year ago

@pamidur Can you please release an official 2.8.3 release (and also update Aspects.Universal to use this latest fixed version 2.8.3 from AspectInjector) ?

pamidur commented 1 year ago

I just released 2.8.2 today. It should contain all the latest fixes. I'll update Aspect.Universal soon

On Fri, 7 Jul 2023, 20:53 Stef Heyenrath, @.***> wrote:

@pamidur https://github.com/pamidur Can you please release an official 2.8.3 release (and also update Aspects.Universal to use this latest fixed version 2.8.3 from AspectInjector) ?

— Reply to this email directly, view it on GitHub https://github.com/pamidur/aspect-injector/issues/217#issuecomment-1625080982, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7HZUEMVNS7ME53RUE5LALXO7E7XANCNFSM6AAAAAAYNOIDAM . You are receiving this because you were mentioned.Message ID: @.***>

StefH commented 1 year ago

@pamidur I'm used the 2.8.2 and 2.8.3-pre1 but for some reason I still get the same issue for an exception in a try-catch ?

image


Could this still be an issue?

pamidur commented 1 year ago

I well could. Please reopen the issue, I'll take a look at exception block behaviour

On Tue, 1 Aug 2023, 17:56 Stef Heyenrath, @.***> wrote:

@pamidur https://github.com/pamidur I'm used the 2.8.2 and 2.8.3-pre1 but for some reason I still get the same issue for an exception in a try-catch ?

[image: image] https://user-images.githubusercontent.com/249938/257418351-65f69674-4f0d-44ea-9922-fbb0dc230d04.png

Note that this method is synchronous.

Could this still be an issue?

— Reply to this email directly, view it on GitHub https://github.com/pamidur/aspect-injector/issues/217#issuecomment-1659616079, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7HZUEQTCNNG2H6I4ODRE3XTCLATANCNFSM6AAAAAAYNOIDAM . You are receiving this because you were mentioned.Message ID: @.***>

StefH commented 1 year ago

@pamidur - I cannot reopen this issue because I did not create it.

pamidur commented 1 year ago

No worries, I'm on it

lezar44 commented 11 months ago

Hello, I've had the same issue with a WPF project using .Net Core 3.1 Downgrading to version 2.4.1 of aspect-injector solved the issue. Hope it can help you.

StefH commented 10 months ago

No worries, I'm on it

Did you have time yet to fix this?

pamidur commented 10 months ago

still looking into it, sorry, don't have much time recently :(

lezar44 commented 7 months ago

I've solved this issue with a split of Around Advice in Before and After. And now the debugger works fine :

        [Advice(Kind.Before, Targets = Target.Method)]
        public void BeforeMethod([Argument(Source.Name)] string name, [Argument(Source.Type)] Type instanceType, [Argument(Source.Arguments)] object[] arguments)

and

        [Advice(Kind.After, Targets = Target.Method)]
        public void AfterMethod([Argument(Source.Name)] string name, [Argument(Source.Type)] Type instanceType, [Argument(Source.Arguments)] object[] arguments, [Argument(Source.ReturnValue)] object result)