Source Generator IDE interaction
I ran into an odd situation where if I generate code for a class with a primary constructor my IDE complains that the partial properties are ambiguous, but if I don’t use a primary constructor it’s fine. And in both cases it builds correctly. I was unable to reproduce in a smaller sample project. Any ideas?
Project with the problem is configured for WPF, .net9.0 and using preview language for partial properties
10 Replies
What source generator?
And take a look at the generated code
I realize it wasn’t clear, this is a source generator that I have written myself. The generated code looks fine, it is just implementing INotifyPropertyChanged using partial properties rather than a field like most public SGs do right now.
CommunityToolkit has that, btw
Right but right now SGs can’t build on each other so I had to implement it myself
Gotcha
Well, take a look at what code the primary constructor generates: sharplab.io
Perhaps there's some conflict there
Like your generator generating fields with the same names as constructor params or some such
The dependencies might not be configured completely too
like the incremental inputs
so the output isn't regenerated properly when you change the source
but on build I think it would always do a run
hence it working on build
SharpLab
C#/VB/F# compiler playground.
This has to be some sort of weird caching issue because I just removed my SG entirely for this class and just added the extra partial definitions in non generated code and still see the same issue.
Could you share the SG repo?
Ended up finding it’s an IDE error and reproducable with no source generators.
https://developercommunity.microsoft.com/t/Partial-Property-on-class-with-Primary-C/10820515
Microsoft Developer Community
Microsoft Developer Community