Is there any way to reference (in XAML) an assembly with spaces in its name?
Asked Answered
F

3

11

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 &quot; around the assembly name doesn't help.

Freehold answered 16/3, 2011 at 18:47 Comment(0)
T
1

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:

<xmlns:local="clr-namespace:Some.Namespace"/>
Trisyllable answered 17/3, 2011 at 11:8 Comment(0)
L
5

This solution seems to have fixed the issue for me with spaces in the assembly name.

Loth answered 29/5, 2012 at 14:21 Comment(0)
T
1

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:

<xmlns:local="clr-namespace:Some.Namespace"/>
Trisyllable answered 17/3, 2011 at 11:8 Comment(0)
C
0

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:

[assembly: XmlnsDefinition("http://company.com/namespace", "Namespace")]
[assembly: XmlnsDefinition("http://company.com/namespace/views", "Namespace.Views")]

Then in your XAML code you can now reference the namespaces like this:

xmlns:views="http://company.com/namespace/views"

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

Communicative answered 27/6, 2024 at 9:47 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.