ArxOne / MrAdvice

.NET aspect weaver (build task under NuGet package)
MIT License
311 stars 45 forks source link

attribute with enum property in standard lib fail #143

Closed HeroXXiv closed 3 years ago

HeroXXiv commented 5 years ago

Hi,

I have a execution project and a library project. The lib proj targets netstandard20 and contains classes with weavers, while the exe proj is targeting netcore21. Some aspect attributes have a enum property, but below exception is thrown when invoking the annotated method.

Unhandled Exception: System.TypeLoadException: Could not load type 'System.ConsoleColor' from assembly 'MrAdviceSamples.Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

ps. everything works fine if the enum is a constructor argument. ps.. also fine when class Bean defined in the exe proj.

    [AttributeUsage(validOn: AttributeTargets.Method)]
    public class MyProudAdvice : Attribute, IMethodAdvice
    {
        public MyProudAdvice()
        {
        }

        public MyProudAdvice(ConsoleColor option)
        {
            Option = option;
        }

        public ConsoleColor Option { get; set; }

        public void Advise(MethodAdviceContext context)
        {
            Console.WriteLine("before");
            context.Proceed();
            Console.WriteLine("after");
        }
    }

    public class Bean
    {
        [MyProudAdvice(Option = ConsoleColor.Black)] // this fails
        //[MyProudAdvice(ConsoleColor.Black)] // this works
        public void MyProudMethod()
        {
            Console.WriteLine("do");
        }
    }
picrap commented 5 years ago

I'm happy that you have a workaround, because that one won't be easy to fix. I'll take a look, thanks.

picrap commented 3 years ago

Seems fixed (not my fault 🤨)