C# VisualStudio报告Roslyn分析器中缺少一个方法,但它确实存在
我正在尝试使用这个分析仪(我写的) 我对这个源文件应用它C# VisualStudio报告Roslyn分析器中缺少一个方法,但它确实存在,c#,json,visual-studio-2015,roslyn,analyzer,C#,Json,Visual Studio 2015,Roslyn,Analyzer,我正在尝试使用这个分析仪(我写的) 我对这个源文件应用它 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 { [DataCo
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:警告CS8032:analyzer的实例
无法从中创建Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer
C:\Users\phelan\workspace\testjson\packages\Weingartner.Json.Migration.analyzers.1.0.4\analyzers\dotnet\cs\Weingartner.Json.Migration.Roslyn.dll
:类型中的方法“获取支持的诊断”
“Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer”来自
程序集'Weingartner.Json.Migration.Roslyn,版本=1.0.6246.21734,
区域性=中性,PublicKeyToken=null'没有
实施
这很奇怪,因为如果我用JustDecompile打开DLL,我会看到
[DiagnosticAnalyzer("C#", new string[] { })]
public class MigrationHashAnalyzer : DiagnosticAnalyzer
{
<snip>
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create<DiagnosticDescriptor>(MigrationHashAnalyzer.Rule);
}
}
<snip>
}
[DiagnosticanAnalyzer(“C#”,新字符串[]{}]
公共类MigrationHashAnalyzer:DiagnosticanAnalyzer
{
公共覆盖ImmutableArray支持的诊断
{
得到
{
返回ImmutableArray.Create(MigrationHashAnalyzer.Rule);
}
}
}
这正是我所期望的,因为分析器的源代码是编译的。如果这个方法真的丢失了,那么它就不会编译
为什么VS会报告一个确实存在的方法丢失了呢?Visual Studio对它使用的库的版本非常挑剔。VS本身使用
System.Collections.Immutable
包。由于您的分析器使用不同的版本,运行时无法找到该方法,并假定尚未实现该方法
参考:
是否存在命名空间不匹配?“Weingartner.Json.Migration.Analyzer”而不是“Weingartner.Json.Migration.Roslyn”?错误显示为Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer,dll包含Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer。完全相同的无论如何,这不是因为它找不到类。它声称类上缺少一个方法。Wierd.System.Collections.Immutable的哪个版本是您引用的?请尝试下拉到。这样就成功了@DavidG你是否介意添加这个作为一个答案,以及你如何知道正确的版本应该是什么。我想我在例行升级过程中更新了ImmutableCollections版本,但没有注意到分析器已损坏。@BradGonesSurfing您的图像似乎有问题。它不会为我显示。@svick之前我也遇到过同样的情况,但我认为imgur出现了加载问题。