pamidur / aspect-injector

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

Generic class with constructor chain cannot be processed #140

Closed levdimov closed 3 years ago

levdimov commented 3 years ago

First of all, thank you for you library! It seems like we may drop our own code and replace it with this beauty.


Generic class (abstract or not) with constructor chain cannot be processed if aspect is set on a class declaration.

Similar to https://github.com/pamidur/aspect-injector/issues/38

Here is an example based on ArgumentsTests:

[ArgumentsTests_MethodAspect]
internal abstract class ArgumentsTests_GenericClassConstructorChainTarget<T> where T : class
{
    public ArgumentsTests_GenericClassConstructorChainTarget()
    {
    }

    public ArgumentsTests_GenericClassConstructorChainTarget(int a) : this()
    {
    }

    public ArgumentsTests_GenericClassConstructorChainTarget(int a, int b) : this(a)
    {
    }

    public void Fact()
    {
    }
}
error AI_ERR0: Processing failure: System.InvalidOperationException: Cannot find base class ctor call
            at FluentIL.MethodEditor.GetCodeStart(MethodBody body) in C:\_work\aspect-injector\external\FluentIL\src\FluentIL\MethodEditor.cs:line 84
            at AspectInjector.Core.Extensions.FluentExtensions.GetUserCodeStart(MethodBody body) in C:\_work\aspect-injector\src\AspectInjector.Core\Extensions\FluentExtensions.cs:line 26
            at AspectInjector.Core.Extensions.FluentExtensions.OnAspectsInitialized(MethodBody body, PointCut action) in C:\_work\aspect-injector\src\AspectInjector.Core\Extensions\FluentExtensions.cs:line 36
            at AspectInjector.Core.Advice.Weavers.Processes.AdviceBeforeProcess.Execute() in C:\_work\aspect-injector\src\AspectInjector.Core.Advice\Weavers\Processes\AdviceBeforeProcess.cs:line 19
            at AspectInjector.Core.Advice.Weavers.AdviceInlineWeaver.WeaveMethod(MethodDefinition method, InjectionDefinition injection) in C:\_work\aspect-injector\src\AspectInjector.Core.Advice\Weavers\AdviceInlineWeaver.cs:line 93
            at AspectInjector.Core.Advice.Weavers.AdviceInlineWeaver.Weave(InjectionDefinition injection) in C:\_work\aspect-injector\src\AspectInjector.Core.Advice\Weavers\AdviceInlineWeaver.cs:line 69
            at AspectInjector.Core.Processor.PatchAssembly(AssemblyDefinition assembly, Boolean optimize, Boolean verbose) in C:\_work\aspect-injector\src\AspectInjector.Core\Processor.cs:line 80
            at FluentIL.PatcherBase.Process(String assemblyFile, IAssemblyResolver resolver, Boolean optimize, Boolean verbose) in C:\_work\aspect-injector\external\FluentIL\src\FluentIL\PatcherBase.cs:line 41
            at FluentIL.PatcherBase.Process(String assemblyFile, IReadOnlyList`1 references, Boolean optimize, Boolean verbose) in C:\_work\aspect-injector\external\FluentIL\src\FluentIL\PatcherBase.cs:line 25
            at AspectInjector.Compiler.Execute(String filename, IReadOnlyList`1 references, Boolean optimize, Boolean verbose) in C:\_work\aspect-injector\src\AspectInjector\Compiler.cs:line 32. Please submit an issue to https://github.com/pamidur/aspect-injector
pamidur commented 3 years ago

Thanks for the report, I'll take a look shortly! I honestly hoped I have ironed all generic-related issues with fire long ago :)

pamidur commented 3 years ago

should be fixed in release 2.4.2

levdimov commented 3 years ago

Unfortunately, inheritors from base class above with another aspect don't work now failing with the same error.

[TestAspect2]
internal class ArgumentsTests_GenericClassConstructorChainTargetImpl : ArgumentsTests_GenericClassConstructorChainTarget<string>
{
}
pamidur commented 3 years ago

Alright, I reopen the issue!

pamidur commented 3 years ago

@levdimov could you please try v2.4.3 ?

levdimov commented 3 years ago

Sorry for late response.

2.4.3 seems to work well. No problems as of yet.