Unhandled exception (PostSharp.Compiler.Hosting.CommandLine.dll 6.0.24 release | .NET Core 2.1.2): System.NullReferenceException: Object reference not set to an instance of an object.

perodiaro's Avatar

perodiaro

04 Aug, 2018 06:45 PM

Got an error at solution build.

Build log:

1>C:\Users\Admin\source\repos\TestDllLoad\TestDllLoad\TestDllLoad.csproj : error PS0099: Unhandled exception (PostSharp.Compiler.Hosting.CommandLine.dll 6.0.24 release | .NET Core 2.1.2): System.NullReferenceException: Object reference not set to an instance of an object.
1>C:\Users\Admin\source\repos\TestDllLoad\TestDllLoad\TestDllLoad.csproj : error PS0099: at PostSharp.Sdk.AspectInfrastructure.TypeInitializationManager.^nCElfVTrtpDd.^Dpi1V+WW(MethodDefDeclaration _0) in ^xo25+YorCGvs:line 630
1>C:\Users\Admin\source\repos\TestDllLoad\TestDllLoad\TestDllLoad.csproj : error PS0099: at PostSharp.Sdk.AspectInfrastructure.TypeInitializationManager.^nCElfVTrtpDd.^WKeyjjZv(TypeDefDeclaration _0, ^IfscAxyN _1, MethodDefDeclaration _2, ^n0mSh9Dz _3) in ^xo25+YorCGvs:line 605
1>C:\Users\Admin\source\repos\TestDllLoad\TestDllLoad\TestDllLoad.csproj : error PS0099: at PostSharp.Sdk.AspectInfrastructure.TypeInitializationManager.^uPjZnkQNGku3.^r4DISfQ8(TypeDefDeclaration _0, ^IfscAxyN& _1) in ^xo25+YorCGvs:line 542
1>C:\Users\Admin\source\repos\TestDllLoad\TestDllLoad\TestDllLoad.csproj : error PS0099: at PostSharp.Sdk.AspectInfrastructure.TypeInitializationManager.^r4DISfQ8() in ^xo25+YorCGvs:line 959
1>C:\Users\Admin\source\repos\TestDllLoad\TestDllLoad\TestDllLoad.csproj : error PS0099: at ^YRTd8AcBbva/.Execute() in ^HpM7ehxuEZEb:line 29
1>C:\Users\Admin\source\repos\TestDllLoad\TestDllLoad\TestDllLoad.csproj : error PS0099: at PostSharp.Sdk.Extensibility.Project.ExecutePhase(String phase) in ^wJ3oIHJDddm/:line 2321
1>C:\Users\Admin\source\repos\TestDllLoad\TestDllLoad\TestDllLoad.csproj : error PS0099: at PostSharp.Sdk.Extensibility.Project.Execute() in ^wJ3oIHJDddm/:line 2388
1>C:\Users\Admin\source\repos\TestDllLoad\TestDllLoad\TestDllLoad.csproj : error PS0099: at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation) in D:\src\PostSharp-5\Core\PostSharp.Hosting\PostSharpObject.cs:line 283.
1>Done building project "TestDllLoad.csproj" -- FAILED.

Source code:

[FinalAspect]
    public interface ITest
    {
    }

    public interface ITestImpl
    {
        bool IsLoaded { get; set; }
    }

    [IntroduceInterface(typeof(ITestImpl), OverrideAction = InterfaceOverrideAction.Ignore)]
    [PSerializable]
    public class TestAspect : InstanceLevelAspect, ITestImpl
    {
        public bool IsLoaded { get; set; } = new Random().Next(0, 100) > 50;
    }

    [PSerializable]
    [MulticastAttributeUsage(Inheritance = MulticastInheritance.Multicast)]
    public class FinalAspect : TypeLevelAspect, IAspectProvider
    {
        public IEnumerable<AspectInstance> ProvideAspects(object targetElement)
        {
            Type targetType = (Type)targetElement;

            if (!HasBaseAspect(targetType) && targetType.GetInterfaces().All(x => x != typeof(ITestImpl)))
            {
                yield return new AspectInstance(targetType, new TestAspect());
            }
        }

        private bool HasBaseAspect(Type targetType)
        {
            IAspectRepositoryService repository = PostSharpEnvironment.CurrentProject.GetService<IAspectRepositoryService>();
            return repository.HasAspect(targetType, typeof(TestAspect)) ||
                   (targetType.BaseType != null && HasBaseAspect(targetType.BaseType));
        }
    }

    public class Test1 : ITest { }
    public class Test2 : ITest { }
    public class Test3 : ITest { }
    public class Test4 : ITest { }
    public class Test5 : ITest { }
    public class Test6 : ITest { }
    public class Test7 : ITest { }
    public class Test8 : ITest { }
    public class Test9 : ITest { }
    public class Test10 : ITest { }
  1. Support Staff 1 Posted by PostSharp Techn... on 06 Aug, 2018 01:54 PM

    PostSharp Technologies's Avatar

    Hello,

    we have successfully reproduced the bug and it seems to be quite old (the same behavior can be observed in PostSharp 4.3). We will be working on a fix.

    Thanks for reporting it.

    (internal issue #16490)

    All the best,
    Daniel

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac