-
Notifications
You must be signed in to change notification settings - Fork 678
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
x:Bind does not work with C# record #5315
Comments
I'm confused about why it's trying to call the setter in the first place? Have you set the defaultbindmode to TwoWay? |
@JohnnyWestlake I have not not set DefaultBindMode. The error occurs when compiling, the setter appears to be generated even though it is not used. |
@RealTommyKlein FYI |
In WinAppSDK 1.0 with dotnet 6.0.1 the situation is still the same. |
I've created a @Marv51 Does the same thing occur if you setup the binding as |
@hawkerm I tested this again just now. XamlTypeInfo.g.cs: private void set_9_BlogPost_Title(object instance, object Value)
{
var that = (global::App1.BlogPost)instance;
that.Title = (global::System.String)Value;
} |
Unfortunately this isn't an easy fix on the WinUI side - the metadata loading/reflection the Xaml compiler is pretty dated and can't access custom modifiers for types, and the |
@RealTommyKlein Thank you very much for explaining what is going on here and what the problems are. |
@StephenLPeters @RealTommyKlein I can confirm this works fine in UWP, but with the same setup the XamlTypeInfo generator for WinUI 3 exhibits this issue w/ 1.0.3. I just hit this building our new sample app in the Toolkit which we're cross-building for UWP and WinUI 3. The UWP head runs fine, but then the WinUI 3 compiler spits out the CS8852 error. I guess I don't understand why the XamlTypeInfo is even bothering to generate setters here at all if the property is only ever being read from in XAML (and not TwoWay bound)? Wouldn't that be the only case where the setter is required anyway? |
Hi there, any update on this? I can of course stop using records and switch back to readonly structs, but that's a bit sad. Thanks! |
Agreed. |
Still not working. I'd really like to use record classes. But I can't when running in WindowsAppSdk... |
I think this is still very important (re: #8638) |
Here too. VERY important as providing a setter would make the messages which MUST be immutable mutable... . To have something "somehow" working I will write setters which will throw an Exception if called twice. But MS should take this issue more serious... |
I hit the property initializer issue today as well. That's quite an oversight I'd also like to see improved. |
Taking a quick look, I think the fix is to be made here: microsoft-ui-xaml/src/src/XamlCompiler/BuildTasks/System.Xaml/System/Xaml/XamlMember.cs Lines 714 to 722 in aeed4c1
See dotnet/runtime#43088 (comment) for how to detect init-only using reflection. This feels like an important scenario. |
Also hit this issue today. Was looking to keep the data structure immutable. |
Describe the bug
I am try to x:bind a c# 9 record to the ItemsSource of an ItemsRepeater, with a corresponding DataTemplate. However, compilation fails with
Steps to reproduce the bug
Version Info
NuGet package version:
WinUI 3 - Windows App SDK 0.8: 0.8.0
Windows app type:
Additional context
The error message is referring to this generated method in XamlTypeInfo.g.cs which tries to set a property on a record:
Init Only Setters also seem to be broken in the same way:
Of course
private set;
can be used as an alternative for now, but support for these features is needed to keep up with .net development. (Or at least a way better error message is needed)The text was updated successfully, but these errors were encountered: