❔ ✅ `System.Runtime` Assembly missing in `CSharpCompilation` when using referenced Attribute
Heya!
I've been playing around with testing source generators and I ran into an odd issue when getting the
What's the issue?
When calling
I've tried to investigate this a little further, following the
https://github.com/dotnet/roslyn/blob/72e0a39fe59cd242dbf441df1f8beae694c8f068/src/Compilers/CSharp/Portable/Compilation/PublicSemanticModel.cs#L20-L21
where
Would anyone happen to know how I can fix this? Am I not referencing the
I've been playing around with testing source generators and I ran into an odd issue when getting the
SymbolInfo of an Attribute that is part of a referenced assembly. I have both the assembly and the Syste.Runtime assembly referenced in the CSharpCompilation which the generator driver is using.What's the issue?
When calling
<SemanticModel>.GetSymbolInfo(<AttributeSyntax>).Symbol I would expect it to return the attribute symbol for the attribute from the referenced assembly. Instead, I get null. I have a minimal reproducible example here: https://github.com/StrawbrryFlurry/CSharpCompilationAttributeReference, which shows this behavior.I've tried to investigate this a little further, following the
GetSymbolInfo call leading me to this line:https://github.com/dotnet/roslyn/blob/72e0a39fe59cd242dbf441df1f8beae694c8f068/src/Compilers/CSharp/Portable/Compilation/PublicSemanticModel.cs#L20-L21
where
attributeType is an ExtendedErrorTypeSymbol, that is able to resolve the namespace of the attribute in the referenced assembly (ReferenceLibrary.ReferencedAttribute) with the error:error CS0012: The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.Would anyone happen to know how I can fix this? Am I not referencing the
System.Runtime Assembly correctly? I'd greatly appreciate any pointing in the right direction 
GitHub
The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs. - dotnet/roslyn