Microsoft.Extensions.Logging.Generators.dll: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0 Culture=neutral, PublicKeyToken= ....'

Gui, Feng 21 Reputation points
2022-02-06T04:58:29.96+00:00

Created a project with Microsoft .Net Core 3.1 in Visual Studio Enterprise Version 16.11.8

Warning CS8032 An instance of analyzer Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator cannot be created from C:\Users\fgui.nuget\packages\microsoft.extensions.logging.abstractions\6.0.0\analyzers\dotnet\roslyn4.0\cs\Microsoft.Extensions.Logging.Generators.dll: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

Warning CS8032 An instance of analyzer Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator cannot be created from C:\Users\fgui.nuget\packages\microsoft.extensions.logging.abstractions\6.0.0\analyzers\dotnet\roslyn3.11\cs\Microsoft.Extensions.Logging.Generators.dll: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

I installed NuGet packages

Microsoft.CodeAnalysis (4.0.0-6.final)
Microsoft.CodeAnalysis.Compilers (4.0.0-6.final)
Microsoft.EntityFrameworkCore.SqlServer (5.0.0)
Microsoft.Extensions.Hosting (6.0.0)
Microsoft.Extensions.Logging (6.0.0)
Microsoft.Net.Compilers (4.0.0-6.final)
Microsoft.Configuration.ConfigurationManager (6.0.0)

I can see Microsoft.Extensions.Logging.Generators.dll in
C:\Users\fgui.nuget\packages\microsoft.extensions.logging.abstractions\6.0.0\analyzers\dotnet\roslyn4.0\cs
C:\Users\fgui.nuget\packages\microsoft.extensions.logging.abstractions\6.0.0\analyzers\dotnet\roslyn3.11\cs

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
697 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,604 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Gui, Feng 21 Reputation points
    2022-02-11T03:18:46.35+00:00

    I deleted the hidden .vs in the solution folder and rebuilt the project in Visual Studio 2019 Enterprise Version 16.11.8. After first rebuild, the warning messages were gone. But they are back later.

    I followed the steps you listed.

    Then I saw the error message

    NuGet package restore failed. Please see Error List window for detailed warnings and errors.
    Error occurred while restoring NuGet packages: Access to the path 'Microsoft.Build.Tasks.CodeAnalysis.dll' is denied.

    However, I can see "Microsoft.Build.Tasks.CodeAnalysis.dll" in
    C:\Users\fgui.nuget\packages\microsoft.net.compilers\4.0.0-6.final\tools


  2. Sven 11 Reputation points
    2022-04-25T08:35:01.873+00:00

    I have the very same problem, but it happens only when deploying over Azure Pipeline (CI/CD). Using a custom instance as build server.

    Downgrading "Microsoft.Extensions.Hosting" and "Microsoft.Extensions.Hosting.Abstractions" to 5.0.0 did not help:

    2022-04-22T15:05:02.6227809Z          Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Roslyn
    2022-04-22T15:05:02.9132106Z ##[warning]CSC(0,0): Warning CS8032: An instance of analyzer Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator cannot be created from C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\microsoft.extensions.logging.abstractions\6.0.0\analyzers\dotnet\roslyn3.11\cs\Microsoft.Extensions.Logging.Generators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
    2022-04-22T15:05:02.9143211Z      9>CSC : warning CS8032: An instance of analyzer Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator cannot be created from C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\microsoft.extensions.logging.abstractions\6.0.0\analyzers\dotnet\roslyn3.11\cs\Microsoft.Extensions.Logging.Generators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. [C:\agent\_work\1\s\BotTranslator\BotTranslator.csproj]
    2022-04-22T15:05:02.9149198Z ##[warning]CSC(0,0): Warning CS8032: An instance of analyzer Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator cannot be created from C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\microsoft.extensions.logging.abstractions\6.0.0\analyzers\dotnet\roslyn4.0\cs\Microsoft.Extensions.Logging.Generators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
    2022-04-22T15:05:02.9151913Z      9>CSC : warning CS8032: An instance of analyzer Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator cannot be created from C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\microsoft.extensions.logging.abstractions\6.0.0\analyzers\dotnet\roslyn4.0\cs\Microsoft.Extensions.Logging.Generators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. [C:\agent\_work\1\s\BotTranslator\BotTranslator.csproj]
    2022-04-22T15:05:02.9156531Z ##[warning]CSC(0,0): Warning CS8032: An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\system.text.json\6.0.0\analyzers\dotnet\roslyn3.11\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
    2022-04-22T15:05:02.9158990Z      9>CSC : warning CS8032: An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\system.text.json\6.0.0\analyzers\dotnet\roslyn3.11\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. [C:\agent\_work\1\s\BotTranslator\BotTranslator.csproj]
    2022-04-22T15:05:02.9163317Z ##[warning]CSC(0,0): Warning CS8032: An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\system.text.json\6.0.0\analyzers\dotnet\roslyn4.0\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
    2022-04-22T15:05:02.9165797Z      9>CSC : warning CS8032: An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\system.text.json\6.0.0\analyzers\dotnet\roslyn4.0\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. [C:\agent\_work\1\s\BotTranslator\BotTranslator.csproj]
    

  3. Martin Florin 1 Reputation point
    2022-08-16T08:51:04.217+00:00

    Are you sure you are using the correct Visual Studio version? This usually happens to me when I open i.e. VS 2019 with a .net 6 solution instead of VS 2022.


  4. 東昇 Shaiken 0 Reputation points
    2023-08-26T10:05:10.31+00:00

    old version no analyzers directory,

    maybe old vs2017 version, i dont know

    so ... my solution

    1. update nuget all package version
    2. close vs2019
    3. delete .vs
    4. reopen vs2019
    5. build project

    build success

    0 comments No comments