C# PostSharp给出了MissingMethodException

C# PostSharp给出了MissingMethodException,c#,.net,postsharp,missingmethodexception,C#,.net,Postsharp,Missingmethodexception,我已经为PostSharp开发了一个自定义方面,它过去工作得很好,但是现在我已经更新了我的项目以使用最新的PostSharp NuGet,所以失败了。这方面的情况如下: [HasConstraint] public sealed class NotDefaultAttribute : LocationContractAttribute, ILocationValidationAspect<ValueType>, ILocationValidationAspect, IAspect {

我已经为PostSharp开发了一个自定义方面,它过去工作得很好,但是现在我已经更新了我的项目以使用最新的PostSharp NuGet,所以失败了。这方面的情况如下:

[HasConstraint]
public sealed class NotDefaultAttribute : LocationContractAttribute, ILocationValidationAspect<ValueType>, ILocationValidationAspect, IAspect
{
    public NotDefaultAttribute()
    {
        ErrorMessage = "The {2} cannot be empty.";
    }

    public Exception ValidateValue(ValueType value, string locationName, LocationKind locationKind)
    {
        if (value == null)
            return null;

        var type = value.GetType();
        if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
        {
            if (value.Equals(Activator.CreateInstance(type.GetGenericArguments()[0])))
                return CreateArgumentException(value, locationName, locationKind);
        }
        else if (value.Equals(Activator.CreateInstance(type)))
            return CreateArgumentNullException(value, locationName, locationKind);

        return null;
    }
}
当代码尝试设置属性时,如本例中所示

new Example().Timestamp = DateTime.UtcNow;
。。。我得到以下
MissingMethodException

System.MissingMethodException: Method not found: 'System.Exception NotDefaultAttribute.ValidateValue(System.ValueType, System.String, PostSharp.Reflection.LocationKind)'.
   at Example.set_Timestamp(DateTime value)

将PostSharp降级到3.0.36可修复此问题。但是,这并不是一个真正的选项,因为我们即将切换到.NET4.5.1,它需要3.0.38或更高版本。(更不用说,被旧版本卡住是一件痛苦的事。)

对所述用例的支持已在PostSharp版本3.1.27中实现。 从该版本开始,可以使用方法
ValidateValue(ValueType value,…)
对任何值类型属性应用验证特性

System.MissingMethodException: Method not found: 'System.Exception NotDefaultAttribute.ValidateValue(System.ValueType, System.String, PostSharp.Reflection.LocationKind)'.
   at Example.set_Timestamp(DateTime value)