ArxOne / MrAdvice

.NET aspect weaver (build task under NuGet package)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

attribute with enum property in standard lib fail

HeroXXiv opened this issue · comments

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");
        }
    }

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

Seems fixed (not my fault 🤨)