Unable to use XamlReader.Load
unless type is already used in a XAML file
#7206
Labels
area-Parser
bug
Something isn't working
product-winui3
WinUI 3 issues
team-Markup
Issue for the Markup team
wct
Describe the bug
It's not possible to use
XamlReader
to parse XAML in an application if the types being parsed aren't already included in a XAML file that was compiled into the app.This may seem like a very niche case but it is very problematic for some testing and library scenarios.
Steps to reproduce the bug
XamlReaderRepo
MainWindow.xaml.cs
, replace the event handler with the following:XamlParseException
.MainWindow.xaml
, add the following immediately under theButton
but above the closing StackPanel tag:Expected behavior
It should be possible to parse a type from a string without having to use it in a XAML file first.
I assume this is failing as some type information is being generated at compile time for everything that is in a .xaml file. Is there a way to trigger this for types not defined in xaml and compiled into the assembly?
Is there some metadata or attributes that can be added to a type definition to enable this? Or some way of specifying namespaces, or assemblies that contain types that the code might want to load as a XAML string.
Based on #4161 (comment) I thought it would be possible to put a
[Windows.UI.Xaml.Data.Bindable]
attribute onMyCoolElement
to enable the expected behavior it does not.Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.0.3
Windows app type
Device form factor
Desktop
Windows version
Windows 11 (21H2): Build 22000
Additional context
Issue discovered as part of work for Windows Community Toolkit. ;)
Possibly also connected to #6299
The text was updated successfully, but these errors were encountered: