.net-6.0asp.net-core-6.0

.NET 6.0 error. Could not load file or assembly System.Diagnostics.PerformanceCounter


I got this error when I set up a .NET Core 6 app:

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.PerformanceCounter, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

I actually added the package reference. It just does not work.

<PackageReference Include="System.Diagnostics.PerformanceCounter" VersionOverride="8.0.0" />

Solution

  • According to your description, I suggest you could firstly make sure you have installed the System.Diagnostics.PerformanceCounter 8.0.0 from the nuget package.

    You could also use this command :

    dotnet add package System.Diagnostics.PerformanceCounter --version 8.0.0
    

    But I suggest you could re-check your project to make sure your project's support version 8 System.Diagnostics.PerformanceCounter.

    Its dependencies as below:

    It need upgrade some package >=8.0.0

    enter image description here

    If your project doesn't support this, I suggest you could install the 6.0.1 instead of the 8.0.0.