In .NET 9 Preview 6, serialization of style using XamlWriter and XamlReader throws exception
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### 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 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 tag for the Fill property.
### Actual behavior
the XAMLWriter has not created the tag for the Fill property.
### Regression?
_No response_
### Known Workarounds
_No response_
### Configuration
Net 9 Preview 6
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.