Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FxCopAnalyzers: An instance of analyzer cannot be created

I'm trying to install fxcop analyzers in my project. However, having added and restored the nuget package, building the project results in hundreds of warnings of the form

1>CSC : warning CS8032: An instance of analyzer Microsoft.CodeAnalysis.VersionCheckAnalyzer.AnalyzerVersionCheckAnalyzer cannot be created from 
C:\<MyProjectPath>\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\analyzers\dotnet\Microsoft.CodeAnalysis.VersionCheckAnalyzer.dll : 
Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. 
The system cannot find the file specified..

However, if I look in the path packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\analyzers\dotnet, I see the dll being mentioned just exists.

Does anyone have any idea what could be going wrong? Maybe some dependency not being met. But if so, how can I tell which? I'm using Visual Studio 2019.

like image 540
chtenb Avatar asked Jul 22 '19 09:07

chtenb


1 Answers

According to your package path C:\<MyProjectPath>\packages, your project targets .net framework. Maybe you have a similar issue like this one.

I can reproduce same issue in one .net framework project in VS2019, and to work around this, I update the Microsoft.Net.Compilers package to latest stable version(3.1.1) and then those warnings disappear. So if you've referenced the Microsoft.Net.Compilers pacakge, update it to latest version. If not, add reference to its latest version.

like image 62
LoLance Avatar answered Sep 20 '22 00:09

LoLance