-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why don't .NET MAUI 9 C# compiled bindings support source-generated properties? #25988
Comments
Hi @egvijayanand, The new compiled bindings are source generated. One design premise of source generators is that they work independently. That is source generator A cannot see the output of source generator B when generating code. So when the compiled bindings are generated we cannot resolve any type information about source generated fields. The XAML style string bindings are resolved using reflection at runtime, so they don't experience those kind of problems. We are aware of this limitation as it also occurs when using XamlG generated code: As for workaround you could either revert to string based bindings (this might affect trimming) or writing the appropriate TypedBinding manually. Under the hood, the new expression-based SetBinding creates an instance of TypedBinding which is then used to call SetBinding(property, typedBinding). |
Why doesn't .NET MAUI assume the existence of such a property, proceed with source generation, and let the build process throw an error if it doesn't match the expectations? This would prevent a cyclical issue. |
In order to assume the existence of some source generated property MAUI would basically need to redo the work of the relevant source generator. So in other words merge them with the MAUI bindings source generator. While yes, this would solve the problem, there is a number of things that would be problematic about it. First, for which source generators do we make assumptions about. How do we choose this set. Second, this would introduce an extremely tight coupling between the generators, every change to them would have to be reflected in MAUI bindings source generator. |
This is clearly a deadlock situation. A potential solution could be to delay the MAUI source generator until build time, allowing other independent source generators, like MVVM Toolkit, to complete their processing. This way, type information is fully available for the MAUI source generator, clearing the way for the project build. Otherwise, it results in an indefinite wait. |
Description
Why don't .NET MAUI 9 compiled bindings support source-generated properties?
When I tried to use the MVVM Toolkit feature for a source-generated property from a backing field and bound it to the newly defined SetBinding call, I received this build error message.
If XAML can work with this property binding, why is C# raising an issue? Support for SG-properties is very crucial in the current context.
Error message: The lambda result type cannot be resolved. Make sure that soruce generated fields / properties are not used in the path.
Public API Changes
Ability to resolve the compilation context with the SG-generated source files.
Intended Use-Case
Potential use of source-generated (SG) toolkits, including the officially supported CommunityToolkit.Mvvm package.
The text was updated successfully, but these errors were encountered: