为什么在 XAML 文件中添加程序集会出现错误?

发布于 2024-08-05 08:06:15 字数 1762 浏览 4 评论 0原文

我有一个像这样动态读取 XAML 文件的应用程序:

StreamReader sr = new StreamReader(pathAndFileName);
this.Content = XamlReader.Load(sr.BaseStream);

在加载的 XAML 文件之一(它们都已删除后面的代码)中,这可以工作:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DynamicXaml123">
    <StackPanel Margin="10" HorizontalAlignment="Left">
        <TextBox Height="23" Width="100" Text="{Binding FirstName}" />
        <TextBox Height="23" Width="100" Text="{Binding LastName}" />
        <TextBox Height="23" Width="100" Text="{Binding Age}" />
        <local:FieldEmailView></local:FieldEmailView>
    </StackPanel>
</UserControl>

但这会给出错误“标签‘FieldEmailView’ XML 命名空间“clr-namespace:DynamicXaml123; assembly=DynamicXaml123”中不存在。

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DynamicXaml123;assembly=DynamicXaml123">
    <StackPanel Margin="10" HorizontalAlignment="Left">
        <TextBox Height="23" Width="100" Text="{Binding FirstName}" />
        <TextBox Height="23" Width="100" Text="{Binding LastName}" />
        <TextBox Height="23" Width="100" Text="{Binding Age}" />
        <local:FieldEmailView></local:FieldEmailView>
    </StackPanel>
</UserControl>

就会出现错误

Message=""XmlNamespace", "Assembly" oder "ClrNamespace"

如果我遗漏了程序集引用,那么在读取 XAML 时

为什么我不能在此处包含程序集引用,我必须更改/检查什么才能使其正常工作?

I've got an application that reads in XAML files dynamically like this:

StreamReader sr = new StreamReader(pathAndFileName);
this.Content = XamlReader.Load(sr.BaseStream);

In one of those XAML files that gets loaded in (they all have had their code behind removed), this works:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DynamicXaml123">
    <StackPanel Margin="10" HorizontalAlignment="Left">
        <TextBox Height="23" Width="100" Text="{Binding FirstName}" />
        <TextBox Height="23" Width="100" Text="{Binding LastName}" />
        <TextBox Height="23" Width="100" Text="{Binding Age}" />
        <local:FieldEmailView></local:FieldEmailView>
    </StackPanel>
</UserControl>

But this give the error "The tag 'FieldEmailView' does not exist in XML namespace 'clr-namespace:DynamicXaml123;assembly=DynamicXaml123'".

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DynamicXaml123;assembly=DynamicXaml123">
    <StackPanel Margin="10" HorizontalAlignment="Left">
        <TextBox Height="23" Width="100" Text="{Binding FirstName}" />
        <TextBox Height="23" Width="100" Text="{Binding LastName}" />
        <TextBox Height="23" Width="100" Text="{Binding Age}" />
        <local:FieldEmailView></local:FieldEmailView>
    </StackPanel>
</UserControl>

If I leave out the assembly reference then it gets the error

Message=""XmlNamespace", "Assembly" oder "ClrNamespace"

when reading in the XAML.

Why can't I include the Assembly reference here, what do I have to change/check to get this to work?

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

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

发布评论

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

评论(2

轮廓§ 2024-08-12 08:06:15

当您加载它时,您需要能够解析程序集引用。换句话说,该程序集必须可供应用程序引用 - 一种方法是将 DynamicXaml123 部署到 GAC。

When you load this in, you need to be able to resolve the assembly references. In other words, this assembly must be available for the application to reference against - one way to do this would be to deploy DynamicXaml123 to the GAC.

灵芸 2024-08-12 08:06:15

我建议退出进程监视器并查看您的应用程序在哪里寻找dynamicxaml123。还要检查融合日志。我猜想如果包含命名空间与不包含命名空间,XamlSerializer 中的行为会有所不同,并且该更改会影响运行时对程序集的影响。

请注意,设置 fuslogvw 和实际开始记录之间可能存在一些延迟。

I'd suggest getting out process monitor and seeing where your app is looking for dynamicxaml123. Check the fusion log as well. I'd guess the behavior in the XamlSerializer is different if you include the namespace than when you don't, and that change is affecting where the runtime is poking around for your assembly.

Note, there may be some lag between setting up fuslogvw and when it actually starts to log.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文