我正在尝试使用这个分析器(我写的)
https://www.nuget.org/packages/Weingartner.Json.Migration.Analyzer/ https://github.com/Weingartner/Migrations.Json.Net
我将它应用于这个源文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Weingartner.Json.Migration;
namespace testjson
{
[DataContract]
[Migratable("")]
public class Class1
{
[DataMember]
public int foo { get; set; }
}
}
我在输出中看到以下警告。
1>CSC : warning CS8032: An instance of analyzer Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer cannot be created from C:\Users\phelan\workspace\testjson\packages\Weingartner.Json.Migration.Analyzer.1.0.4\analyzers\dotnet\cs\Weingartner.Json.Migration.Roslyn.dll : Method 'get_SupportedDiagnostics' in type 'Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer' from assembly 'Weingartner.Json.Migration.Roslyn, Version=1.0.6246.21734, Culture=neutral, PublicKeyToken=null' does not have an implementation..
这很奇怪,因为如果我用 JustDecompile 打开 DLL,我会看到
[DiagnosticAnalyzer("C#", new string[] { })]
public class MigrationHashAnalyzer : DiagnosticAnalyzer
{
<snip>
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create<DiagnosticDescriptor>(MigrationHashAnalyzer.Rule);
}
}
<snip>
}
这是我所期望的,因为分析器的源代码可以编译。如果该方法确实缺失,则无法编译。
为什么 VS 会报告缺少方法,而实际上它确实存在?
最佳答案
Visual Studio 对其使用的库版本非常讲究。 VS 本身使用 version 1.1.36 System.Collections.Immutable
包。由于您的分析器使用不同的版本,运行时无法找到该方法并假定它尚未实现。
引用:https://johnkoerner.com/code-analysis/creating-a-code-analyzer-using-f/#comment-3073977270
关于c# - Visual Studio 报告 Roslyn 分析器中缺少方法,但它确实存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42510558/