Mark H
Mark H

Reputation: 71

Error compiling with PostSharp 4.3.20

When I try to compile from inside Visual Studio 2015 I am getting the following error trace. Has anyone else experienced this?

Error       Unhandled exception (4.3.20.0, postsharp-net40-x86-srv.exe, CLR 4.0.30319.394271, Release): System.NullReferenceException: Object reference not set to an instance of an object.
   at PostSharp.Sdk.CodeModel.GenericMap.GetGenericParameter(GenericParameterKind kind, Int32 ordinal)
   at PostSharp.Sdk.CodeModel.TypeSignatures.GenericParameterTypeSignature.MapGenericArguments(GenericMap genericMap)
   at PostSharp.Sdk.CodeModel.MethodDefDeclaration.WriteReflectionName(StringBuilder stringBuilder, ReflectionNameOptions options, NameMapper mapper)
   at PostSharp.Sdk.CodeModel.WriteReflectionNameExtensions.GetDisplayName(IWriteReflectionName declaration)
   at PostSharp.Sdk.Extensibility.Licensing.LocalLicenseManager.^BLnBYDPkLE/l(MetadataDeclaration _0, TypeDefDeclaration _1, List`1 _2, List`1 _3, ^hjDNKkMra\+ry _4)
   at PostSharp.Sdk.AspectWeaver.AspectWeaver.^Rb+2eJKK(MetadataDeclaration _0)
   at PostSharp.Sdk.AspectWeaver.AspectWeaverInstance.ProvideAdviceTransformations(AspectWeaverTransformationAdder adder)
   at PostSharp.Sdk.AspectWeaver.AspectWeaverTask.^5t5Tu4zL(AspectWeaverInstance _0)
   at PostSharp.Sdk.AspectWeaver.AspectWeaverTask.^vPCloP06(IMetadataDeclaration _0, AspectWeaverInstance _1)
   at PostSharp.Sdk.AspectInfrastructure.StructuredDeclarationDictionary`1.^lNgKC+Z4(IMetadataDeclaration _0, Func`3 _1)
   at PostSharp.Sdk.AspectInfrastructure.StructuredDeclarationDictionary`1.^RdBVqi\.M.^8/pSq47Q(IMetadataDeclaration _0)
   at PostSharp.Sdk.AspectInfrastructure.StructuredDeclarationDictionary`1.^d+wOzSPF(IMetadataDeclaration _0, Func`2 _1)
   at PostSharp.Sdk.AspectInfrastructure.StructuredDeclarationDictionary`1.^+g+TCqVg(TypeDefDeclaration _0, Func`2 _1, Set`1 _2)
   at PostSharp.Sdk.AspectInfrastructure.StructuredDeclarationDictionary`1.^fJqG(Func`2 _0)
   at PostSharp.Sdk.AspectInfrastructure.StructuredDeclarationDictionary`1.^fJqG(Func`3 _0)
   at PostSharp.Sdk.AspectWeaver.AspectWeaverTask.Execute()
   at PostSharp.Sdk.Extensibility.Project.ExecutePhase(String phase)
   at PostSharp.Sdk.Extensibility.Project.Execute()
   at PostSharp.Hosting.PostSharpObject.ExecuteProjects()
   at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation).

Edit: In attempting to produce a sample project for this I was able to isolate the cause. We had an OnMethodBoundary aspect (an in-house logging one) applied to a type with public static implicit operator T(Editable<T> item). When I told PostSharp to exclude this method the problem went away.

So to reproduce it, apply an OnMethodBoundary to a generic implicit operator, while using an Express license.

[ExceptionLoggerAspect]
class Challenged<T>
{
    public T Value { get; set; }

    public static implicit operator T(Challenged<T> item)
    {
        return item.Value;
    }
}

Upvotes: 1

Views: 1106

Answers (1)

Mark H
Mark H

Reputation: 71

The work-around I ended up using was to use AttributeExclude = true on a generically typed implicit operator, which our OnMethodBoundaryAspect was being multicast on to.

[ErrorLoggingAspect(AttributeExclude = true)]
public static implicit operator T(Editable<T> item) 
{ 
  ... 
}

Upvotes: 1

Related Questions