I ported my .NET 5.0 application to .NET 6.0 and now I found that the source-code generator fails. It shows the following error:
Generator 'PermissionGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Adding <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> to the property-group of the generator's project-file didn't really help. It does add System.Collection.Immutable.dll to the output folder (6.0.21.52210), but I still get the same error.
My generator is a .NET Standard 2.0 project, which might not be necessary anymore with .NET 6. So I also tried setting the runtime for the generator to .NET 6. This failed with another error:
An instance of analyzer ... cannot be created from ... Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
It seems that this is an issue with Paket v6 that seems to have a problem when used in conjunction with source-generators. I now use the traditional approach (including the analyzers directly in the project-file) and it now works again. I filed an issue with Paket (link).
I fixed this issue in my project by downgrading Microsoft.CodeAnalysis.CSharp to version 4.0.1. I guess newer versions have an issue finding System.Collections.Immutable.
This is with my source generator on netStandard2.0 and the project the source was being generated for on net6.0.
Related
I'm upgrading my solution from .NET 5 to .NET 6 and getting the error at runtime
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'NLog.Web.AspNetCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c'. The system cannot find the file specified.
File name: 'NLog.Web.AspNetCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c'
at MyApp.Program.CreateHostBuilder(String[] args)
at MyApp.Program.Main(String[] args) in ..\MyApp\Program.cs:line 18
I'm using NLog 4.7.15, and NLog.Web.AspNetCore 4.15.0 nuget packages. The versions did not change during upgrade. As soon as I upgraded all my projects in the solution, I started getting that error at runtime, both on Windows and macOS. As soon as I switch back to .NET 5 the error goes away. I tried upgrading to NLog 5.0.0-rc2 and I get the same error but just Version=5.0.0.0. Downgrading the packages had no effect either.
I'm also using JetBrains Rider.
I'm clueless how to approach this problem. I've searched the web and haven't found any working solutions.
Appears to be a bug in .NET 6
Having this property in the project file was causing the issue
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
Removing it solved it. Not the best solution as I need to use that property. Will have to open up an issue with .NET team.
EDIT: Created an issue with them: https://github.com/dotnet/runtime/issues/68720
I have converted .NET Framework 3.5 TestAPP to .NET 6 TestAPP and worked well.
i have an Automation project(C++ project) which was using .NET Framework 3.5 TestAPP.dll to run the tests, but right now i have replaced the .NET Framework 3.5
.dll with .NET 6 TestAPP i.e. TestAPP.dll
when i ran the exe in command line , i have got an error as
"Unhandled Exception: System.IO.FileLoadException: Could not load file
or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)"
Please let me know if anything needs to be corrected.
Resolved the error by changing the C++/CLI properties from visual studio project properties , which was referring to .NET framework earlier and i have changed the property as .NET core runtime(clr:netcore) and it is internally handled all GAC changes and worked well.
Hope it might help someone .
When upgrading an app to a later .NET version, edit your csproj file and make sure there is no <RuntimeFrameworkVersion> node in there that someone may have inserted manually.
This will not be updated automatically when switching .NET versions
The running project returned this error. When I changed it to the way in the image, the error was solved.
Project>Properties
In my case the error was due to worng Default Project in Package Manager Console, if you are running EF migrations or something that is in a project that need to get info from the API make sure you are targetting the right project, also try clean + build first.
I'm getting System.IO.FileNotFoundException error while trying to add a .net standard library into .net framework project's references.
I have created a .net standard project which contains some other .net standard nuggets in its references, and it's output is a dll which I have inserted it as a reference in a .net framework library (actually it is a unit test project for it). But as I told before it always show me this error:
Message: Test method xDetector.Test.IntegreatedTest.TestMethod threw
exception: System.IO.FileNotFoundException: Could not load file or
assembly 'xFramework.NetCore.xDetector, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file specified.
I have try several ways like editing cproj file and adding other changing visual studio version (which currently is 2019) but no success.
Where the problem may come from?
I am looking to use the System.ServiceProcess.ServiceController class in a .NET Standard 2.0 project. In order to do so I downloaded the Microsoft.Windows.Compatibility packet from NuGet, whic includes among other things ( I also tried to simply download the System.ServiceProcess.ServiceController packet by itself). I can now use the ServiceController without any problem within my class, but when I try to run the program I get:
System.IO.FileNotFoundException: Could not load file or assembly 'System.ServiceProcess.ServiceController, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I guess I'm missing something crucial here, especially since as far as I can tell the version I installed is 4.5.0 and the version it is looking for is the 4.2.1.0. What am I doing wrong?
I have a NetStandard 1.6 library that references an external library (System.Runtime.Loader, fetched from NuGet). If I reference my NetStandard library from a Net Framework 4.7 Windows-application I get a System.IO.FileNotFoundException when running the Net Framework application.
Full exception:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Now, I know full what the exception message means but I haven't got the foggiest on how to solve it in this situation.
Ideas?
I advise you to right click on the visual studio solution, go to manage nuget packages for the solution and check the versions of the various libraries you have. Any conflicts between the libraries will be present in the 'consolidate' tab. Alternatively, try removing the library reference from the project's reference folder and adding it back.