Strawby
❔ ✅ `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
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 36 replies
❔ Generic entity type in EF Core
Heya everyone! the recommended way to work with entities that have a property with a generic type on them? e.g:
I'd like to serialize and deserialize the data as JSON with a config that looks something like this: (I don't need to query the JSON data in the db)
Sadly though, that doesn't seem to work as I get an error saying:
- Do I dynamically add a type configuration for all constructed generic types using reflection? - Do I change the property to be a string and serialize / deserialize it myself? - Do I do something entirely different? :0
The entity type 'MetricsEntity<TestMetricData>' was not found
. (I do have the model builder configured to use all type builders of the assembly)
What's the preferred way to implement this? - Do I dynamically add a type configuration for all constructed generic types using reflection? - Do I change the property to be a string and serialize / deserialize it myself? - Do I do something entirely different? :0
44 replies