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" />
3
- Use the Version attribute instead of VersionOverride.
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="8.0.0" />
- Ensure the package is restored and installed correctly.
dotnet restore
- Ensure you’re targeting a compatible version of .NET and running on Windows.
- Clean and rebuild commands are your friend.
- Check Assembly Binding Redirects (for .NET Framework)
- Check your .csproj file for the target framework:
<TargetFramework>net6.0</TargetFramework>
`
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.PerformanceCounter" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
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
If your project doesn’t support this, I suggest you could install the 6.0.1 instead of the 8.0.0.