我有一个包含多个项目的WPF企业级解决方案。代码在VS 2013中构建良好,在VS 2015中代码不构建。
我试过了:
在解决方案中,我也提到了Prism'和团结'两人都是MS。问题是我甚至都不知道'这种情况正在发生,因为堆栈跟踪错误只是提到了项目而不是特定的类或位置,而不是参考' PostSharp'命名空间。就是这样:
'Severity Code Description Project File Line Suppression State
Error An unexpected exception occurred when executing user code: System.InvalidCastException: Unable to cast object of type 'System.Reflection.RuntimeConstructorInfo' to type 'System.Reflection.MethodInfo'.
at PostSharp.Patterns.Model.NotifyPropertyChanged.DependencyAnalysis.PropertiesDependenciesAnalyzer.MethodAnalyzer.TryGetDependsOn(IMethodCallExpression expression, List`1& invocationPaths, List`1& messages)
at PostSharp.Patterns.Model.NotifyPropertyChanged.DependencyAnalysis.PropertiesDependenciesAnalyzer.MethodAnalyzer.VisitMethodCallExpression(IMethodCallExpression expression)
at PostSharp.Reflection.Syntax.SyntaxTreeVisitor.VisitSyntaxElement(ISyntaxElement syntaxElement)
at PostSharp.Reflection.Syntax.SyntaxTreeVisitor.VisitStatementExpression(IStatementExpression statementExpression)
at PostSharp.Reflection.Syntax.SyntaxTreeVisitor.VisitSyntaxElement(ISyntaxElement syntaxElement)
at PostSharp.Reflection.Syntax.SyntaxTreeVisitor.VisitBlockExpression(IBlockExpression instructionBlock)
at PostSharp.Reflection.Syntax.SyntaxTreeVisitor.VisitSyntaxElement(ISyntaxElement syntaxElement)
at PostSharp.Reflection.Syntax.SyntaxTreeVisitor.VisitBlockExpression(IBlockExpression instructionBlock)
at PostSharp.Reflection.Syntax.SyntaxTreeVisitor.VisitMethodBody(ISyntaxMethodBody methodBody)
at PostSharp.Patterns.Model.NotifyPropertyChanged.DependencyAnalysis.PropertiesDependenciesAnalyzer.MethodAnalyzer.AnalyzeMethodRecursive(MethodBase method)
at PostSharp.Patterns.Model.NotifyPropertyChanged.DependencyAnalysis.PropertiesDependenciesAnalyzer.MethodAnalyzer.AnalyzeProperty(Type type, PropertyInfo propertyInfo, ExplicitDependencyMap currentTypeExplicitDependencyMap)
at PostSharp.Patterns.Model.NotifyPropertyChanged.DependencyAnalysis.PropertiesDependenciesAnalyzer.AnalyzeType(Type type)
at PostSharp.Patterns.Model.NotifyPropertyChangedAttribute.CompileTimeInitialize(Type type, AspectInfo aspectInfo)
at PostSharp.Sdk.AspectWeaver.AspectWeavers.TypeLevelAspectWeaverInstance.^RDzfO2to.^XTF+fjOj()
at PostSharp.Sdk.Utilities.ExceptionHelper.ExecuteUserCode(MessageLocation messageLocation, Action userCode, Type[] acceptableExceptions). Namespace.Project D:\TFS\SourceCodeLocation\POSTSHARP
答案 0 :(得分:0)
事实证明,即使将“严格”的“编译”选项设置为“开启”,VS 2013和2015也允许以某种方式非常简单,但PostSharp不会。
Private _DateDeactivated As Nullable(Of Date)
<SafeForDependencyAnalysis>
Public Property DateDeactivated As Nullable(Of Date)
Get
If MyRequest.DateDeactivated.HasValue Then
IsDeactivated = True
Return MyRequest.DateDeactivated.Value
Else
Return New Nullable(Of Date)
End If
End Get
Set(value As Nullable(Of Date))
_DateDeactivated = value
End Set
End Property
这一行
Return MyRequest.DateDeactivated.Value
应该只是:
Return MyRequest.DateDeactivated
这不是我的代码,但导致更大的解决方案无法在VS 2015中使用PostSharp进行编译。我更担心PostSharp无法提供对实际文件的引用。我想通过刚刚浏览文件和评论属性和方法的蛮力,直到我获得构建成功,然后浏览文件,直到我发现错误。可能有更好的验证工具,如ReSharper可能已经捕获它,但它的工作原理。这可能对某人有所帮助,但可能没有。
答案 1 :(得分:0)
这是[NotifyPropertyChanged]
方面的错误,应在版本4.2.26和4.3.9中修复。如果不是这样,请告诉我。
问题在于VB编译器生成用于处理Nullable<T>
的IL代码的方式 - 对属性依赖性的分析根本没想到。