【发布时间】:2017-02-28 22:16:17
【问题描述】:
我正在尝试使用这个分析器(我写的)
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:警告 CS8032:分析器实例 Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer 无法从 C:\Users\phelan\workspace\testjson\packages\Weingartner.Json.Migration.Analyzer.1.0.4\analyzers\dotnet\cs\Weingartner.Json.Migration.Roslyn.dll : 类型中的方法 'get_SupportedDiagnostics' 'Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer' 来自 程序集'Weingartner.Json.Migration.Roslyn,版本=1.0.6246.21734, Culture=neutral, 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>
}
这是我所期望的,因为分析器的源代码已编译。如果确实缺少该方法,那么它将无法编译。
为什么 VS 会在一个方法确实存在时报告它丢失?
【问题讨论】:
-
会不会有命名空间不匹配? “Weingartner.Json.Migration.Analyzer”而不是“Weingartner.Json.Migration.Roslyn”?
-
错误提示 Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer 并且 dll 包含 Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer。完全相同的。无论如何,它不是找不到类。它声称该类中缺少一个方法。奇怪。
-
您引用的是哪个版本的
System.Collections.Immutable? -
尝试下拉到version 1.1.36。
-
成功了。 @DavidG您是否介意将此作为答案以及您实际上如何知道正确的版本应该是什么。我想我在例行升级过程中更新了 ImmutableCollections 版本,然后没有注意到分析器坏了。
标签: c# json visual-studio-2015 roslyn analyzer