Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DaemonSharps opened this issue May 24, 2023 · 13 comments
Open
Labels

Comments

@DaemonSharps
Copy link

DaemonSharps commented May 24, 2023

Environment:

  • OS: windows
  • Framework: net6.0
  • Type of application: Nunit Test Application
  • Version of AspectInjector: 2.8.1

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
#71

@DaemonSharps DaemonSharps changed the title Name"test" does not exist in the current context in synchronous method Local variables in sync methods are not visible in the VS debugger May 24, 2023
@pamidur
Copy link
Owner

pamidur commented Jun 7, 2023

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 pamidur closed this as completed in cbafc5a Jun 9, 2023
@pamidur pamidur reopened this Jun 9, 2023
@pamidur
Copy link
Owner

pamidur commented Jun 9, 2023

please see if 2.8.2-pre3 fixes it for you?

@DaemonSharps
Copy link
Author

DaemonSharps commented Jun 22, 2023

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

@StefH
Copy link
Contributor

StefH commented Jul 7, 2023

@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
Copy link
Owner

pamidur commented Jul 7, 2023 via email

@StefH
Copy link
Contributor

StefH commented Aug 1, 2023

@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

  • Note that this method is synchronous. But the main method flow is async.
  • This is an old .NET Framework 4.8 style project

Could this still be an issue?

@pamidur
Copy link
Owner

pamidur commented Aug 1, 2023 via email

@StefH
Copy link
Contributor

StefH commented Aug 1, 2023

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

@pamidur
Copy link
Owner

pamidur commented Aug 1, 2023

No worries, I'm on it

@pamidur pamidur reopened this Aug 1, 2023
@lezar44
Copy link

lezar44 commented Sep 14, 2023

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
Copy link
Contributor

StefH commented Oct 6, 2023

No worries, I'm on it

Did you have time yet to fix this?

@pamidur
Copy link
Owner

pamidur commented Oct 6, 2023

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

@lezar44
Copy link

lezar44 commented Jan 8, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants