FxCopAnalyzers: An instance of analyzer cannot be created
Asked Answered
T

3

7

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.

Thyroiditis answered 22/7, 2019 at 9:35 Comment(0)
T
7

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.

Thermic answered 23/7, 2019 at 9:5 Comment(2)
This is very plausible, because I do use an old version of Microsoft.Net.Compilers, and if I remove that dependency it works. Unfortunately I cannot afford to upgrade that package at this point.Thyroiditis
It doesn't work, I used toolset Microsoft.Net.Compilers.toolset 3.8.0Kirima
S
0

If you have a version of Microsoft.CodeAnalysis.FxCopAnalyzers that is too high for your version of Visual Studio you can get this warning

warning CS8032 ...

To find the max version supported see this documentation: Install FxCop analyzers in Visual Studio -> FxCopAnalyzers package versions

Submicroscopic answered 9/11, 2020 at 15:16 Comment(0)
L
0

I've got rid of these errors by upgrading the following nugger

Microsoft.Net.Compilers
Lithuanian answered 18/8, 2021 at 17:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.