3

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?

bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
  • can there be a namespace mismatch? "Weingartner.Json.Migration.Analyzer" as opposed to "Weingartner.Json.Migration.Roslyn"? – Cee McSharpface Feb 28 '17 at 13:56
  • The error says __Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer__ and the dll has __Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer__. Identical. Anyway it is not that it cannot find the class. It is claiming that a method is missing on the class. Wierd. – bradgonesurfing Feb 28 '17 at 13:59
  • What version of `System.Collections.Immutable` are you referencing? – DavidG Feb 28 '17 at 14:02
  • there are three possibly related posts, have a look: http://stackoverflow.com/q/39615981/1132334 and especially http://stackoverflow.com/a/14521695/1132334 and yet better http://stackoverflow.com/a/948787/1132334 – Cee McSharpface Feb 28 '17 at 14:03
  • Version 1.2.1.0 of System.Collections.Immutable – bradgonesurfing Feb 28 '17 at 14:04
  • Possible duplicate of [TypeLoadException says 'no implementation', but it is implemented](http://stackoverflow.com/questions/948785/typeloadexception-says-no-implementation-but-it-is-implemented) – Cee McSharpface Feb 28 '17 at 14:05
  • 1
    Try dropping down to [version 1.1.36](https://www.nuget.org/packages/System.Collections.Immutable/1.1.36) instead. – DavidG Feb 28 '17 at 14:05
  • 1
    That did the trick. @DavidG Would you mind adding this as an answer along with how you actually know what the correct version should be. I think I updated the ImmutableCollections version during a routine upgrade process and then didn't notice the analyzer was broken. – bradgonesurfing Feb 28 '17 at 14:10

1 Answers1

3

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

bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
DavidG
  • 113,891
  • 12
  • 217
  • 223
  • @bradgonesurfing There seems to be something wrong with your image. It doesn't display for me. – svick Feb 28 '17 at 18:35
  • @svick Same thing happened for me earlier, but I think imgur were having load issues. – DavidG Feb 28 '17 at 18:36