c# - Visual Studio 报告 Roslyn 分析器中缺少方法,但它确实存在

标签 c# json visual-studio-2015 roslyn analyzer

我正在尝试使用这个分析器(我写的)

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

enter image description here

关于c# - Visual Studio 报告 Roslyn 分析器中缺少方法,但它确实存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42510558/

相关文章:

c# - ASP.net MVC 应用程序中出现“指定的转换无效”错误。在本地工作,发布后一段时间,但随后抛出错误

c# - 在 Microsoft 的 MVC 和 Javascript 之间共享本地化 ui 字符串的规范方法是什么?

c# - 运行具有连续值返回的多个线程(ping 程序)

c++ - Visual Studio 2015 (C++) : Stop compile on first build error (not first project)

visual-studio-2008 - 使用 Visual Studio 2015 进行 Windows Mobile 6.5.3 开发

c# - 当所述线程正在执行 Console.ReadLine 时,如何中止 .NET 中的另一个线程?

c# - 序列化列表计数而不是列表

java - 无法转换为 JSONArray 以在 ListView 中显示

json - 使用 Flutter 从 Firebase DataSnapshot 获取嵌套的 JSON

visual-studio-2015 - 为什么 Resharper 无法在空的 MSVS 2015 控制台应用程序中检测到未使用的引用?