Skip to content
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

Microsoft.UI.Xaml.Markup.Compiler generates invalid code for init only properties (binding to records) #6701

Closed
adamplonka opened this issue Feb 9, 2022 · 2 comments
Labels
area-XamlCompiler product-winui3 WinUI 3 issues team-Markup Issue for the Markup team

Comments

@adamplonka
Copy link

adamplonka commented Feb 9, 2022

Describe the bug

Tried to use a record as a one way view model but it seems impossible. Microsoft.UI.Xaml.Markup.Compiler generates code like:

        private void set_3_Item_Name(object instance, object Value)
        {
            var that = (global::App5.Item)instance;
            that.Name = (global::System.String)Value;
        }

which generates error CS8852: Init-only property or indexer 'ISomething.Property' can only be assigned in an object initializer, or on 'this' or 'base' in an instance constructor or an 'init' accessor.

Steps to reproduce the bug

  1. Create a record type like public record ReadOnlyModel(string Name);
  2. Try to bind to it using {x:Bind Name, Mode=OneTime}
  3. The project doesn't compile

Expected behavior

Able to bind to properties with init accessor just like to "get only" properties.

Screenshots

No response

NuGet package version

1.0.0

Packaging type

Packaged (MSIX), Unpackaged

Windows version

Windows 11 version 21H2 (22000)

IDE

Visual Studio 2022-preview, Visual Studio 2022

Additional context

No response

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Feb 10, 2022
@btueffers btueffers transferred this issue from microsoft/WindowsAppSDK Feb 10, 2022
@StephenLPeters StephenLPeters added area-XamlCompiler product-winui3 WinUI 3 issues team-Markup Issue for the Markup team labels Mar 4, 2022
@StephenLPeters
Copy link
Contributor

@RealTommyKlein I think this is a dupe but I can't find the issue.

@michael-hawker
Copy link
Collaborator

🦙 Duplicate of #5315

@ghost ghost removed the needs-triage Issue needs to be triaged by the area owners label Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-XamlCompiler product-winui3 WinUI 3 issues team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

3 participants