Copyright © 2026 Unity Technologies
How to reproduce:
1. Open the “Generic_Query_Bug” project
2. Open the “GenericQueryTest” script
3. Uncomment line 22 and save the script
4. Back in Editor observe the Console
Expected result: “GenericQueryTest” script compiles without any errors
Actual result: “GenericQueryTest” script throws “System.InvalidCastException” error
Reproduced with: 1.0.8 (2022.2.21f1, 2023.1.0b18, 2023.2.0a16)
Could not test with: 0.17.0-preview.41 (2022.2.21f1, 2023.1.0b18, 2023.2.0a16) (Package scripting errors), 0.17.0-preview.41 (2020.3.48f1, 2021.3.26f1), 1.0.8 (2020.3.48f1, 2021.3.26f1) (Package not supported)
Reproduced on: Windows 11
Full error log:
Assets\GenericQueryTest.cs(18,1): error SGICE002: This error indicates a bug in the DOTS source generators. We'd appreciate a bug report (Help -> Report a Bug...). Thanks! Error message: 'System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.TypeParameterSymbol' to type 'Microsoft.CodeAnalysis.INamedTypeSymbol'. |--| at Unity.Entities.SourceGen.SystemGenerator.SystemAPI.Query.IdiomaticCSharpForEachDescription.<TryGetQueryDatas>g__TryGetIdiomaticCSharpForEachQueryType|73_0(ITypeSymbol typeSymbol, Location errorLocation) |--| at Unity.Entities.SourceGen.SystemGenerator.SystemAPI.Query.IdiomaticCSharpForEachDescription.TryGetQueryDatas(ICollection`1& queryTypes) |--| at Unity.Entities.SourceGen.SystemGenerator.SystemAPI.Query.IdiomaticCSharpForEachDescription..ctor(SystemDescription systemDescription, QueryCandidate queryCandidate, Int32 numForEachsPreviouslySeenInSystem) |--| at Unity.Entities.SourceGen.SystemGenerator.SystemAPI.Query.IdiomaticCSharpForEachModule.RegisterChangesInSystem(SystemDescription systemDescription) |--| at Unity.Entities.SourceGen.SystemGenerator.SystemGenerator.Execute(GeneratorExecutionContext context)'
Issues you vote on will appear here