In .NET 9 Preview 6, serialization of style using XamlWriter and XamlReader throws exception
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
The Setter.Value was made optional so the writer is theoretically fine, but the reader should be able to deal with that.
@KarkuvelRajan - This issue has been fixed with PR - https://github.com/dotnet/wpf/pull/9229. Please check.
Hi @anjali-wpf,
Can you please update on which version of the Net9 this fix will be available?