Specific line-break placement in the xaml Resources causes XamlCompiler error WMC0610: The XAML Binary Format (XBF) generator reported syntax error '0xc00cee23'
Describe the bug
XamlCompiler reports WMC0610 when a resource declared after ResourceDictionary.MergedDictionaries uses a very specific line-break arrangement.
The following XAML reproduces the issue:
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries><ContentDialog
x:Name="DiskUsageDialog">
</ContentDialog>
</ResourceDictionary>
</Page.Resources>I got the extremely cryptic error message WMC0610 from the xaml compiler reports:
XamlCompiler error WMC0610: The XAML Binary Format (XBF) generator reported syntax error '0xc00cee23'Why is this important?
The issue depends on both of the following formatting conditions:
</ResourceDictionary.MergedDictionaries><ContentDialog
x:Name="DiskUsageDialog">- There must be no line break between:
</ResourceDictionary.MergedDictionaries><ContentDialog- There must be a line break between
<ContentDialogandx:Name:
<ContentDialog
x:Name="DiskUsageDialog">Changing either line break causes the XAML to compile successfully.
For example, adding a line break before <ContentDialog> compiles successfully:
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
<ContentDialog
x:Name="DiskUsageDialog">
</ContentDialog>
</ResourceDictionary>
</Page.Resources>Likewise, keeping the elements adjacent but moving x:Name onto the same line also compiles successfully:
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries><ContentDialog x:Name="DiskUsageDialog">
</ContentDialog>
</ResourceDictionary>
</Page.Resources>Therefore, these semantically equivalent XAML documents produce different XBF compiler results solely because of whitespace placement.
Steps to reproduce the bug
Steps to reproduce the bug
- Create a WinUI 3 project.
- Add an empty resource dictionary at
Themes/Generic.xaml. - Add the following XAML to a
Page:
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries><ContentDialog
x:Name="DiskUsageDialog">
</ContentDialog>
</ResourceDictionary>
</Page.Resources>
<Grid />- Build the project.
The build fails with:
XamlCompiler error WMC0610: The XAML Binary Format (XBF) generator reported syntax error '0xc00cee23'Change either of the two relevant line breaks:
- insert a line break between
</ResourceDictionary.MergedDictionaries>and<ContentDialog>, or - remove the line break between
<ContentDialogandx:Name.
- insert a line break between
Build again.
The XAML now compiles successfully.
Actual behavior
Only this particular combination:
</ResourceDictionary.MergedDictionaries><ContentDialog
x:Name="DiskUsageDialog">causes:
WMC0610: The XAML Binary Format (XBF) generator reported syntax error '0xc00cee23'Changing either line break makes the error disappear.
This appears to be a whitespace-sensitive parsing or XBF generation issue rather than an invalid XAML construct.
Expected behavior
Whitespace and line-break placement between XML elements and attributes should not affect the semantics of the XAML.
All of the following forms should produce the same result:
</ResourceDictionary.MergedDictionaries><ContentDialog
x:Name="DiskUsageDialog"></ResourceDictionary.MergedDictionaries>
<ContentDialog
x:Name="DiskUsageDialog"></ResourceDictionary.MergedDictionaries><ContentDialog x:Name="DiskUsageDialog">At minimum, the XBF generator should not enter a syntax-error state based only on this formatting difference.
Screenshots
NuGet package version
2.4.0
Windows version
No response
Additional context
No response
Source: microsoft/microsoft-ui-xaml