使用 PostSharp 4.3.20 编译时出错
Error compiling with PostSharp 4.3.20
当我尝试从 Visual Studio 2015 内部编译时,我收到以下错误跟踪。有没有其他人遇到过这种情况?
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).
编辑:在尝试为此生成示例项目时,我能够找出原因。我们将 OnMethodBoundary 方面(内部日志记录方面)应用于具有 public static implicit operator T(Editable<T> item)
的类型。当我告诉 PostSharp 排除这个方法时,问题就消失了。
因此,要重现它,请将 OnMethodBoundary 应用于通用隐式运算符,同时使用 Express 许可证。
[ExceptionLoggerAspect]
class Challenged<T>
{
public T Value { get; set; }
public static implicit operator T(Challenged<T> item)
{
return item.Value;
}
}
我最终使用的解决方法是在通用类型的隐式运算符上使用 AttributeExclude = true,我们的 OnMethodBoundaryAspect 被多播到该运算符上。
[ErrorLoggingAspect(AttributeExclude = true)]
public static implicit operator T(Editable<T> item)
{
...
}
当我尝试从 Visual Studio 2015 内部编译时,我收到以下错误跟踪。有没有其他人遇到过这种情况?
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).
编辑:在尝试为此生成示例项目时,我能够找出原因。我们将 OnMethodBoundary 方面(内部日志记录方面)应用于具有 public static implicit operator T(Editable<T> item)
的类型。当我告诉 PostSharp 排除这个方法时,问题就消失了。
因此,要重现它,请将 OnMethodBoundary 应用于通用隐式运算符,同时使用 Express 许可证。
[ExceptionLoggerAspect]
class Challenged<T>
{
public T Value { get; set; }
public static implicit operator T(Challenged<T> item)
{
return item.Value;
}
}
我最终使用的解决方法是在通用类型的隐式运算符上使用 AttributeExclude = true,我们的 OnMethodBoundaryAspect 被多播到该运算符上。
[ErrorLoggingAspect(AttributeExclude = true)]
public static implicit operator T(Editable<T> item)
{
...
}