© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•14mo ago•
23 replies
Okno

Source generator unable to resolve external type

I am writing a source generator to learn csharp and I stubbled into something strange.

Here is the
IncrementalValueProvider
IncrementalValueProvider
in my source generator:
        var mapToPipeline = context.SyntaxProvider.ForAttributeWithMetadataName(
            fullyQualifiedMetadataName: "CartographeAutomatique.MapToAttribute",
            predicate: static (syntaxNode, _) => syntaxNode is TypeDeclarationSyntax,
            transform: static (context, _) => PopulateTypeMapping(context, MappingKind.MapTo)
        );
        var mapToPipeline = context.SyntaxProvider.ForAttributeWithMetadataName(
            fullyQualifiedMetadataName: "CartographeAutomatique.MapToAttribute",
            predicate: static (syntaxNode, _) => syntaxNode is TypeDeclarationSyntax,
            transform: static (context, _) => PopulateTypeMapping(context, MappingKind.MapTo)
        );


It generate mapping code for a class A to a class B and is used like so:
[MapTo(typeof(Point3))]
public class Vector3
{
    public float X { get; set; }
    public float Y { get; set; }
    public float Z { get; set; }
}
[MapTo(typeof(Point3))]
public class Vector3
{
    public float X { get; set; }
    public float Y { get; set; }
    public float Z { get; set; }
}


Everything work as expected as long as the attribute parameter (here 


Everything work as expected as long as the attribute parameter (here 
typeof(Point3)
)) is accessible in the current package.
If the typeof attribute parameter lives in an external package the 
)) is accessible in the current package.
If the typeof attribute parameter lives in an external package the 
PopulateTyypeMapping
 method is never called by the 
 method is never called by the 
IncrementalValueProvider`. I think I understand that the compiler is unable to resolve the class so it skip the attribute, but it's very puzzling that there is no error message or warning emitted at compile time.

Am I missing something or is there a way to make this work without changing the attribute parameter to something else ?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

source generator
C#CC# / help
3y ago
❔ Source generator & protobuf
C#CC# / help
4y ago
❔ Unable to resolve service type for IHttpClientFactory
C#CC# / help
3y ago
✅ Unable to create migration - 'Unable to resolve service for type 'DbContextOptions'
C#CC# / help
2y ago