bradgonesurfing bradgonesurfing -4 years ago 145
C# Question

Visual Studio reports a missing method in a Roslyn Analyser but it is definitely there

I'm trying to use this analyser ( I wrote it )

https://www.nuget.org/packages/Weingartner.Json.Migration.Analyzer/
https://github.com/Weingartner/Migrations.Json.Net

I apply it against this source file

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; }
}
}


and I see the following warning in the output.


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..


which is quite strange because if I crack open the DLL with JustDecompile I see

[DiagnosticAnalyzer("C#", new string[] { })]
public class MigrationHashAnalyzer : DiagnosticAnalyzer
{
<snip>
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create<DiagnosticDescriptor>(MigrationHashAnalyzer.Rule);
}
}
<snip>
}


which is what I expect because the source for the analyzer compiles. If the method was really missing then it wouldn't compile.

Why would VS report a method missing when it is really there?

Answer Source

Visual Studio is quite particular about the version of the libraries it uses. VS itself uses version 1.1.36 of the System.Collections.Immutable package. Since your analyser uses a different version, the runtime is unable to find the method and assumes it hasn't been implemented.

Reference: https://johnkoerner.com/code-analysis/creating-a-code-analyzer-using-f/#comment-3073977270

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download