C
C#2w ago
Mormon Son

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
Angius
Angius2w ago
What source generator? And take a look at the generated code
Mormon Son
Mormon SonOP2w ago
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.
Angius
Angius2w ago
CommunityToolkit has that, btw
Mormon Son
Mormon SonOP2w ago
Right but right now SGs can’t build on each other so I had to implement it myself
Angius
Angius2w ago
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
Anton
Anton2w ago
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
Mormon Son
Mormon SonOP2w ago
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.
SleepWellPupper
Could you share the SG repo?
Mormon Son
Mormon SonOP5d ago
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

Did you find this page helpful?