有什么方法可以引用(在 XAML 中)名称中带有空格的程序集吗?
是否无法引用名称中包含空格的程序集?我真的必须重命名程序集以使其不包含空格吗?难道没有办法逃离空间吗?我找不到很多遇到此问题的人的实例,更不用说任何解决方案了...
示例 XAML:
<UserControl x:Class="SomeClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Some.Namespace;assembly=Some Assembly With Spaces In The Name"
>
这是当您尝试执行此操作时编译器给出的错误:
未知生成错误,“clr-namespace:Some.Namespace; assembly=名称中包含空格的某些程序集”映射 URI 无效。第 4 行位置 2。'
把 ' 或 "程序集名称周围没有帮助。
Is it not possible to reference an assembly that has spaces in its name? Do I really have to rename my assemblies to not contain spaces? Is there no way to escape the spaces? I can't find very many instances of people who have this problem, let alone any solutions...
Example XAML:
<UserControl x:Class="SomeClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Some.Namespace;assembly=Some Assembly With Spaces In The Name"
>
And this is the error that the compiler gives you when you try to do this:
Unknown build error, ''clr-namespace:Some.Namespace;assembly=Some Assembly With Spaces In The Name' mapping URI is not valid. Line 4 Position 2.'
Putting ' or " around the assembly name doesn't help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此解决方案似乎已经为我解决了程序集名称中存在空格的问题。
This solution seems to have fixed the issue for me with spaces in the assembly name.
这看起来像您所指的错误,已“修复”...
我刚刚在单独的程序集中遇到了类似的 ValueConverter 问题,以及构建它的方法是在我的 ValueConverter 类中包含一个默认构造函数。如果没有它,如果它包含在名称中带有空格的程序集中,VS 将不会构建它。
不幸的是,它构建了,但当我实际运行它时,它因
XamlParseException
而失败。如果我对没有空格的程序集执行相同的操作,则一切都很好。
顺便说一句,您正在定义 xmlns:local 命名空间,但引用不同的程序集 - 如果您的命名空间确实是本地的,您可以执行以下操作:
This looks like the bug you're referring to, which is 'fixed'...
I've just had a similar problem with a ValueConverter in a separate assembly, and the way to get it to build was to include a default constructor in my ValueConverter class. Without that, VS won't build it if it's contained in an assembly with spaces in the name.
Unfortunately, it builds but then falls over with a
XamlParseException
when I actually run it up.If I do the same referencing an assembly without spaces, everything is fine.
As an aside, you're defining the
xmlns:local
namespace but referencing a different assembly - if your namespace is indeed local you can just do:如果您不想重命名程序集,则可以将这些行添加到您需要外部引用的每个命名空间的
AssemblyInfo.cs
中:然后,在您的 XAML 代码中,您现在可以像这样引用命名空间:(
这个答案与这个现有的非常相似,但是那个答案有一个链接,并且还直接将装饰添加到命名空间,当我尝试时这对我不起作用)
If you don't want to rename your assembly, you can add these lines to your
AssemblyInfo.cs
for every namespace you need to reference externally:Then in your XAML code you can now reference the namespaces like this:
(this answer is really similar to this existing one but that one has a link and also adds the decoration to the namespace directly, which didn't work for me when I tried)