【问题标题】:uwp xaml parsing failed with class library dlluwp xaml 解析失败,类库 dll
【发布时间】:2019-06-04 13:53:41
【问题描述】:

我有一个非常简单的 uwp 应用程序,我在其中引用了一个类库,该类库显然也是一个 uwp 项目并具有自定义 ContentDialog。当我直接将它作为一个项目引用时,它就可以正常工作,并且 ContentDialog 也会打开。但是,当我删除项目并使用其生成的 dll(调试模式为 Debug,发布模式为 Release)并引用该 dll 时,我在该 ContentDialog 的构造函数中得到一个 xaml Parse 异常。

UWP 客户端应用代码

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);  
    }
}

Test() 方法引发异常,但堆栈跟踪(通过断点确认)导致该自定义 contentDialog 的构造函数中的 InitializeComponent() 方法。

类库项目中的方法

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

自定义内容对话框的 xaml

<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代码

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

类库项目被一个“windows运行时组件”项目引用,该项目是一个后台任务,客户端应用程序引用了这个后台任务,但我认为这无关紧要,因为这是一个xaml解析异常,而后台任务不是甚至在发生异常时注册

【问题讨论】:

  • 库是否与主项目具有相同的最低和目标 Win 10 版本?
  • 你想在后台任务中显示对话框吗?
  • 您的项目结构看起来很复杂,您介意分享一个简单的示例吗?
  • 遇到同样的错误,你找到解决办法了吗!?
  • 我也在尝试显示来自类库的内容对话框,这是一个 dll。我收到了这个 XamlParseException。任何人都可以帮忙!

标签: c# xaml uwp windows-runtime xamlparseexception


【解决方案1】:

如果您在 ARM64 目标上看到此问题,则可以通过将其添加到您的项目中来解决此问题:

<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>

基本上,XAML/.NET 层在 ARM64 上的工作方式不同,并且在该边界处存在问题。我的理解是 Windows SDK 人员正在努力解决这个问题。

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 2019-10-16
    • 2022-10-22
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    相关资源
    最近更新 更多