Muhammad Touseef
Muhammad Touseef

Reputation: 4465

uwp xaml parsing failed with class library dll

I have a very simple uwp app in which I refer to a class library which is also a uwp project obviously and has a Custom ContentDialog. When I reference it directly as a project then it works just fine and the ContentDialog opens as well. But when I remove the project and use its produced dll ( Debug for debug mode and Release for Release mode ) and refer that dll then I get a xaml Parse exception in the constructor of that ContentDialog.

UWP client app code

public sealed partial class MainPage : Page
{
    private async Task Test()
    {
        var exitNode = new ExitNodeCode.ExitNode();
        await exitNode.AskForPermissionPopup();
    }

    public MainPage() => InitializeComponent();

    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        await Test();
        base.OnNavigatedTo(e);  
    }
}

the exception is thrown on Test() method but the stacktrace ( confirmed with breakpoint ) leads to the InitializeComponent() method in constructor of that custom contentDialog.

Method in class library project

public async Task AskForPermissionPopup()
{
    var dialog = new PermissionDialog();
    await dialog.ShowAsync();                
}

xaml for Custom content Dialog

<ContentDialog
    x:Class="ExitNodeCode.PermissionDialog"
    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"
    mc:Ignorable="d"
    PrimaryButtonText="I Agree!"
    SecondaryButtonText="Maybe Later"
    PrimaryButtonClick="PermissionDialog_PrimaryButtonClick"
    SecondaryButtonClick="PermissionDialog_SecondaryButtonClick">
    <Grid >           
    </Grid>
</ContentDialog>

cs code for the dialog

public sealed partial class PermissionDialog : ContentDialog
{
    public PermissionDialog()
    {
        InitializeComponent();
    }
}

the class library project is referenced by a "windows runtime component" project which is a background task and client app references this background task, but I think that is irrelevant here because this is a xaml parse exception and the background task is not even registered when exception occurs

Upvotes: 6

Views: 344

Answers (1)

MattWhilden
MattWhilden

Reputation: 1696

If you're seeing this on ARM64 targets, it's possible this can be resolved by adding this to your project:

<ProperytGroup>
    <!-- ARM64 builds for managed apps use .NET Native. We can't use the Reflection Provider for that. -->
    <EnableTypeInfoReflection Condition="'$(Configuration)' == 'ARM64'">false</EnableTypeInfoReflection>
</ProperytGroup>

Essentially, the XAML/.NET layer works differently on ARM64 and there's an issue at that boundary. My understanding is that the Windows SDK folks are working to address this.

Upvotes: 1

Related Questions