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

aspect-injector autogenerated methods are displayed in stacktrace #156

Open
alexsanv opened this issue Jun 4, 2021 · 7 comments
Open

aspect-injector autogenerated methods are displayed in stacktrace #156

alexsanv opened this issue Jun 4, 2021 · 7 comments

Comments

@alexsanv
Copy link

alexsanv commented Jun 4, 2021

Probably this is a duplicate of #30, but I can reproduce this issue in 2.5.0

using System;
using AspectInjector.Broker;

namespace aspect_injector_sampple
{
    [SampleAspect]
    class Program
    {
        public static void Main(string[] args)
        {
            throw new Exception("Sample Exception");
        }
    }

    [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class)]
    [Aspect(Scope.Global)]
    [Injection(typeof(SampleAspectAttribute))]
    public class SampleAspectAttribute : Attribute
    {
        [Advice(Kind.Around, Targets = Target.Method | Target.Public)]
        public object Handle(
            [Argument(Source.Target)] Func<object[], object> target,
            [Argument(Source.Arguments)] object[] args,
            [Argument(Source.Name)] string methodName,
            [Argument(Source.ReturnType)] Type returnType)
        {
           return target(args);
        }
    }
}

Stacktrace:
image

@pamidur
Copy link
Owner

pamidur commented Jun 11, 2021

Hi @alexsanv , sorry for delay and thanks for your report!
I'll take a look at it asap!

In any case it isn't always possible to hide parts of stacktrace, do you have any specific usecase where for example you parse stacktrace or is it just a matter of convenience?

@alexsanv
Copy link
Author

@pamidur, this mostly is a matter of convenience.
But there may be a valid use case, let me describe.

I implemented a helper library\nuget package for NUnit which uses aspect-injector to catch exceptions thrown in NUnit methods (e.g OneTimeSetup) wrapped around (Kind.Around) by aspect.

When you investigate a test failure, probably the first thing you look at is the exception's stacktrace. Having aspect-injector's autogenerated methods in exception's stacktrace in test failure may confuse people who are not familiar with the aspect-injector itself or don't even know that it is used in solution (directly or indirectly, as in my case with the library that uses aspect-injector).

Does this use case make any sense?

@pamidur
Copy link
Owner

pamidur commented Jun 13, 2021

Yes, totally.
What was done before - we mark our methods with the attributes that prevent those methods appear in the stacktrace in a debugger (read - visual studio)

To hide them completely we'll need other approach, wild guess - either process the stacktrace and hide frames or probably properly rethrowing exceptions might work as well. Or maybe there are some other attributes to try. Anyway it requires investigation

@jerviscui
Copy link
Contributor

#153

@pamidur
Copy link
Owner

pamidur commented Aug 16, 2021

@jerviscui , yes it makes sense. With Kind.Exception it is up to user to decide how stack trace looks

@pamidur pamidur removed the bug label Jan 16, 2022
@Dreamescaper
Copy link

Would it make sense to add StackTraceHiddenAttribute for auto-generated methods?

@pamidur
Copy link
Owner

pamidur commented Apr 27, 2022

omg it exists :)
but it seems like it is only for net6 and higher

AspectInjector supports all libs that can target netstandard2,0 and netstandard2,0 does not have StackTraceHiddenAttribute

though I believe we can add this attribute only if target assembly is net6

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

No branches or pull requests

4 participants