Loading XAML at Runtime Works in Debug, Not in Release

112 Views Asked by At

In a release build, XamlReader.Load fails trying to read the 3rd party control from Windows Community Toolkit shown in the example. It also fails whenever it tries to read some of my custom controls, but not others. None of them fail to read in debug builds.

I have a minimal test project repro here. Runs fine in debug, fails in release.

I have no idea how this could be happening. If it's a UWP restriction why would it work in debug builds?

MainPage.xaml.cs

public MainPage()
{
    this.Loaded += MainPage_Loaded;
    this.InitializeComponent();
}

private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    var xamlStr = File.ReadAllText("TestView.xaml");
    try
    {
        var runtimeXaml = XamlReader.Load(xamlStr) as UserControl;
        this.Content = runtimeXaml;
    }
    catch (Exception ex)
    {
        var messageDialog = new MessageDialog(ex.Message);
        await messageDialog.ShowAsync();
    }
}

TestView.xaml

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:media="using:Microsoft.Toolkit.Uwp.UI.Media"
    mc:Ignorable="d">

    <Grid Width="400" Height="400">
        <Grid.Background>
            <media:AcrylicBrush TintColor="Orange" BlurAmount="4" />
        </Grid.Background>
        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
            Runtime XAML Loaded Successfully!</TextBlock>
    </Grid>
</UserControl>
0

There are 0 best solutions below