Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Tag does not exist in XML namespace"

To illustrate the issue, I have created a simple sample project where I am getting compilation errors on the XAML definition.

Here is my class definition:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MVVMTest.Foo
{
    public class FooTestClass
    {
        public String Name { get; set; }

        public String Key { get; set; }
    }
}

It should be noted that FooTestClass resides in the Foo subfolder (of the MVVMTest folder)

Here is my XAML:

<Window x:Class="MVVMTest.MainWindow"
        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:local="clr-namespace:MVVMTest"
        xmlns:mView="clr-namespace:MVVMTest.Foo;assembly=MVVMTest"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">

    <Window.Resources>
        <mView:FooTestClass x:Key="ddd" />           
    </Window.Resources>
    <Grid>
    </Grid>
</Window>

I'm getting the following error message

The tag 'FooTestClass' does not exist in XML namespace 'clr-namespace:MVVMTest.Foo;assembly=MVVMTest'. Line 12 Position 10.
MVVMTest C:\Dev Projects\MVVMTest\MVVMTest\MainWindow.xaml

Is there an issue in VS?

like image 918
JohnB Avatar asked Feb 01 '17 20:02

JohnB


2 Answers

You should not specify the name of the assembly if the type is defined in the same assembly as the window:

xmlns:mView="clr-namespace:MVVMTest.Foo"

An exception from this rule is when you load some XAML markup dynamically using the XamlReader.Parse method. Then you must specify the assembly name even if the type resides in the same assembly.

like image 132
mm8 Avatar answered Oct 29 '22 11:10

mm8


I've found yet another reason why this error may occur, so I'll leave it here for future readers.

If the namespace solution doesn't work, make sure your project and your DLL are both targeting the same framework versions.

Menu Project -> Properties

enter image description here

like image 3
a'' Avatar answered Oct 29 '22 11:10

a''