4

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.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Ramon de Klein
  • 5,172
  • 2
  • 41
  • 64

2 Answers2

0

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).

Ramon de Klein
  • 5,172
  • 2
  • 41
  • 64
0

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.

user3797758
  • 829
  • 1
  • 14
  • 28