© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
35 replies
Strawb

❔ ✅ `System.Runtime` Assembly missing in `CSharpCompilation` when using referenced Attribute

Heya! GuraWave2

I've been playing around with testing source generators and I ran into an odd issue when getting the
SymbolInfo
SymbolInfo
of an Attribute that is part of a referenced assembly. I have both the assembly and the
Syste.Runtime
Syste.Runtime
assembly referenced in the
CSharpCompilation
CSharpCompilation
which the generator driver is using.

What's the issue?
When calling
<SemanticModel>.GetSymbolInfo(<AttributeSyntax>).Symbol
<SemanticModel>.GetSymbolInfo(<AttributeSyntax>).Symbol
I would expect it to return the attribute symbol for the attribute from the referenced assembly. Instead, I get
null
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
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
attributeType
is an
ExtendedErrorTypeSymbol
ExtendedErrorTypeSymbol
, that is able to resolve the namespace of the attribute in the referenced assembly (
ReferenceLibrary.ReferencedAttribute
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'.
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
System.Runtime
Assembly correctly? I'd greatly appreciate any pointing in the right direction Smile
GitHub
roslyn/src/Compilers/CSharp/Portable/Compilation/PublicSemanticMode...
The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs. - dotnet/roslyn
roslyn/src/Compilers/CSharp/Portable/Compilation/PublicSemanticMode...
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ CSharpCompilation using Roslyn
C#CC# / help
3y ago
❔ The type 'Attribute' is defined in an assembly that is not referenced.
C#CC# / help
4y ago
❔ Missing assembly reference using PackageReference
C#CC# / help
3y ago
error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute
C#CC# / help
8mo ago