XamlReader.Load(XmlReader)“堆栈为空” Xaml解析异常

发布于 2024-07-18 03:42:31 字数 640 浏览 3 评论 0原文

我正在尝试在运行时加载 xaml 文件。 我的代码如下所示:

StringReader stringReader = new StringReader(xamlString);           
            XmlReader xmlReader = XmlReader.Create(stringReader);
            content = XamlReader.Load(xmlReader);

它基本上是 msdn 的复制粘贴。 XamlReader.Load 行抛出 XamlParseException,并带有“Stack Empty at line....”的内部异常。
它指向的行是在 xaml 字符串中找到的用户控件的结束标记,即该字符串的最后一行。

基本的 Xaml 结构如下,

<UserControl>
    <UserControl.Resources>
    </UserControl.Resources>
    <Grid>
    </Grid>
</UserControl>

谷歌搜索没有找到任何结果。 非常感谢任何帮助找到解决方案的帮助。

I'm trying to load a xaml file at runtime. My code looks like this:

StringReader stringReader = new StringReader(xamlString);           
            XmlReader xmlReader = XmlReader.Create(stringReader);
            content = XamlReader.Load(xmlReader);

It's basically copy paste of of msdn. the XamlReader.Load line throws a XamlParseException with an inner exception of "Stack Empty at line....".
The line it points to is the closing tag of the user control found in the xaml string, the last line of the string.

The basic Xaml structure is as follows

<UserControl>
    <UserControl.Resources>
    </UserControl.Resources>
    <Grid>
    </Grid>
</UserControl>

Googling didn't turn anything up. Any help in find a solution is much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半夏半凉 2024-07-25 03:42:31

我刚刚开始从 xaml 中删除块,直到错误消失。 我能够将其范围缩小到在用户控件声明中找到的这一行,

<UserControl
...
WPFManagement:ObjectReference.Declaration="{WPFManagement:ObjectReference thisPointer}"
...>

不完全确定为什么会抛出 Stack Empty 异常,但确实如此。

这是整个标题,其中罪魁祸首以粗体显示

<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:WPFManagement="clr-namespace:A;assembly=A"
         xmlns:WPFControls="clr-namespace:B;assembly=B"
         xmlns:ModuleUI="clr-namespace:C;assembly=C"
         xmlns:GeneralUI="clr-namespace:D;assembly=D"
         **WPFManagement:ObjectReference.Declaration="{WPFManagement:ObjectReference thisPointer}"**
         mc:Ignorable="d"
         WPFControls:UIExtension.Caption="Filler"
         WPFControls:UIExtension.Icon="Icon"
         d:DesignWidth="910"
         d:DesignHeight="730">

I just started chopping blocks out of my xaml until the error went away. I was able to narrow it down to this line found in my user control declaration

<UserControl
...
WPFManagement:ObjectReference.Declaration="{WPFManagement:ObjectReference thisPointer}"
...>

Not exactly sure why that throws a Stack Empty exception, but it does.

Here is the entire Header with the culprit in bold

<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:WPFManagement="clr-namespace:A;assembly=A"
         xmlns:WPFControls="clr-namespace:B;assembly=B"
         xmlns:ModuleUI="clr-namespace:C;assembly=C"
         xmlns:GeneralUI="clr-namespace:D;assembly=D"
         **WPFManagement:ObjectReference.Declaration="{WPFManagement:ObjectReference thisPointer}"**
         mc:Ignorable="d"
         WPFControls:UIExtension.Caption="Filler"
         WPFControls:UIExtension.Icon="Icon"
         d:DesignWidth="910"
         d:DesignHeight="730">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文