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

In .NET 9 Preview 6, serialization of style using XamlWriter and XamlReader throws exception #9384

Open
KarkuvelRajan opened this issue Jul 11, 2024 · 3 comments
Assignees

Comments

@KarkuvelRajan
Copy link

KarkuvelRajan commented Jul 11, 2024

Description

In .NET 9 Preview 6, serialization and deserialization of style using XamlWriter and XamlReader throws exception. But in .NET 8 and other framework versions, it works fine. Please find the code below.

In .NET 9 Preview 6, most of the setter tags do not have <Setter.Value> tags in the output file which results in the exception.

public string filePath = "style.xml";

StringWriter stringWriter = new StringWriter();

// for saving
Style style = new Style(typeof(System.Windows.Shapes.Path));
style.Setters.Add(new Setter(System.Windows.Shapes.Path.StretchProperty, Stretch.Fill));
style.Setters.Add(new Setter(System.Windows.Shapes.Path.FillProperty, Brushes.Black));            

System.Windows.Markup.XamlWriter.Save(style, stringWriter);

File.WriteAllText(filePath, stringWriter.ToString());

// for loading

string xamlContent = File.ReadAllText(filePath);

// Parse the XAML content back into a Style object
using (StringReader stringReader = new StringReader(xamlContent))
{
    using (XmlReader xmlReader = XmlReader.Create(stringReader))
    {
        Style loadedStyle = (Style)XamlReader.Load(xmlReader);                    
    }
}

Reproduction Steps

Use the above codes to replicate the issue.

Expected behavior

Like other Net Frameworks and Core versions, the XAMLWriter should create the <Setter.Value> tag for the Fill property.

Actual behavior

the XAMLWriter has not created the <Setter.Value> tag for the Fill property.

Regression?

No response

Known Workarounds

No response

Configuration

Net 9 Preview 6

Other information

No response

@MichalStrehovsky MichalStrehovsky transferred this issue from dotnet/runtime Jul 11, 2024
@miloush
Copy link
Contributor

miloush commented Jul 11, 2024

The Setter.Value was made optional so the writer is theoretically fine, but the reader should be able to deal with that.

@pchaurasia14 pchaurasia14 added Investigate Requires further investigation by the WPF team. and removed Untriaged labels Jul 11, 2024
@anjali-wpf
Copy link
Member

@KarkuvelRajan - This issue has been fixed with PR - #9229. Please check.

@anjali-wpf anjali-wpf added 📭 waiting-author-feedback To request more information from author. and removed Investigate Requires further investigation by the WPF team. labels Jul 21, 2024
@KarkuvelRajan
Copy link
Author

Hi @anjali-wpf,

Can you please update on which version of the Net9 this fix will be available?

@dotnet-policy-service dotnet-policy-service bot removed the 📭 waiting-author-feedback To request more information from author. label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants