dotnet / roslyn-analyzers

MIT License
1.58k stars 464 forks source link

BC42376 - An instance of analyzer cannot be created #1814

Closed dan-drews closed 5 years ago

dan-drews commented 6 years ago

Analyzer package

Microsoft.CodeAnalysis.Analyzers

Package Version

Example: v2.6.1

Diagnostic ID

[BC42376 ](unable to find MS link to it)

Info

We have created an analyzer that we are trying to install as a nuget package to our solution. We added it to each of our projects (.net framework 4.7.2), which are a mix of vb and cs, and a mix of Class Libraries, Console Apps, and Web Apps.

The analyzer works perfectly in all of the class libraries, and as far as I can tell, it is working in all of the console apps as well (I spot-checked a couple), but on the web application (Asp.net web forms, vb.net) I am receiving the following error:

Severity Code Description Project File Line Suppression State Error BC42376 An instance of analyzer BTAnalyzer.PageInheritanceAnalyzer cannot be created from C:\dev\Branches\DEVELOPMENT\Dan\packages\BTAnalyzer.1.0.0.6\analyzers\dotnet\vb\BTAnalyzer.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

If it matters, here are the packages referenced by the analyzer, they are all set to PrivateAssets="all": "Microsoft.CodeAnalysis.Analyzers" Version="2.6.1" "Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.9.0" "Microsoft.CodeAnalysis.VisualBasic" Version="2.9.0" "Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="2.9.0" "Microsoft.CodeAnalysis.Workspaces.Common" Version="2.9.0" "NETStandard.Library"

EDIT With Additional information When building with TFS, the error seems to be happening for more projects (Seemingly all projects). The build begins on the first project and it immediately fails with the following error:

[warning]CSC(0,0): Warning CS8032: An instance of analyzer BTAnalyzer.PageInheritanceAnalyzer cannot be created from C:\Users\MSAPRTFSBL0102$.nuget\packages\btanalyzer\1.0.0.8\analyzers\dotnet\cs\BTAnalyzer.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

This is a warning on csproj files and an error on vbproj files

VS Info:

Microsoft Visual Studio Professional 2017 Version 15.8.4 VisualStudio.15.Release/15.8.4+28010.2026 Microsoft .NET Framework Version 4.7.03062

Installed Version: Professional

Application Insights Tools for Visual Studio Package 8.13.10627.1 Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.8.05085.0 ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.8.31590 Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017 5.2.60618.0 For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.8.05023.0 Azure App Service Tools v3.0.0

BuildMonitorPackage 1.0 Monitor builds in Visual Studio.

C# Tools 2.9.0-beta8-63208-01 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Code Converter 1.0 Code Converter Extension Details

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.1.49 (remotes/origin/d15-8@ee674f3) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

JavaScript Language Service 2.0 JavaScript Language Service

Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.10730.2

Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 1.0 Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Mono Debugging for Visual Studio 4.11.8-pre (009db7d) Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61808.07020 Microsoft SQL Server Data Tools

Syntax Visualizer 1.0 An extension for visualizing Roslyn SyntaxTrees.

TypeScript Tools 15.8.20801.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.9.0-beta8-63208-01 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.2 for F# 4.5 15.8.0.0. Commit Hash: c55dd2c3d618eb93a8d16e503947342b1fa93556. Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

Xamarin 4.11.0.756 (d15-8@b66ff7180) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.14.221 (a73ca07f7) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 1.1.116 (9619170) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.0.0.19 (HEAD/a8a3b0ec7) Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 11.14.0.13 (373c313) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

dan-drews commented 5 years ago

Is there anybody who is free to take a look at this, or get me pointed in the right direction?

NetMastr5 commented 5 years ago

Dan, did you ever get anywhere with this error? I have attempted to write a custom analyzer for out projects and am seeing the same issue here, where machines are unable to find the 'Microsoft.CodeAnalysis, Version=2.9.0.0 despite the visual studio instances being 15.8.9 and that version being in Visual Studio's own install directory.

dan-drews commented 5 years ago

I did not

mavasani commented 5 years ago

@dan-drews @NetMastr5 This seems likely to be same issue as https://github.com/dotnet/roslyn-analyzers/issues/1533, where building with TFS fails as the underlying compiler toolset version during build on server is a lower one. Can you check if the workaround mentioned there helps?

In general, you can you reference the following documentation pages to find if your analyzer and Microsoft.CodeAnalysis versions are correct:

  1. For FxCop analyzers package versions: https://docs.microsoft.com/en-us/visualstudio/code-quality/install-fxcop-analyzers?view=vs-2017#fxcopanalyzers-package-versions
  2. For Microsoft.CodeAnalysis package versions: https://review.docs.microsoft.com/en-us/visualstudio/extensibility/roslyn-version-support?view=vs-2017
dan-drews commented 5 years ago

@mavasani I do not have access to that second link: "We are sorry, the page is forbidden. You do not have permission with this credential, please sign out to try with others and go back again."

333fred commented 5 years ago

The correct link is https://docs.microsoft.com/en-us/visualstudio/extensibility/roslyn-version-support?view=vs-2017.

mavasani commented 5 years ago

@dan-drews Did that resolve your issue?

dan-drews commented 5 years ago

@mavasani I have not yet had a chance to dig into this, as priorities have shifted. We can probably close this issue out and I can reopen when I have a chance to investigate further