tag does not exist in XML namespace
Asked Answered
T

11

33

This error seems to be posted all over the place but each one seems to have its own solution, none of which solved my problem.

I am getting an error for a Resource Dictionary I am making (and later merging) that the tag 'ModelBindings' does not exist in XML namespace 'clr-namespace:Company.Project.Module.Folder;assembly=Company.Project.Module'

The assembly I am referencing is custom and contained within the solution. Not only that but we have looked at the dll put into the bin for the project the Resource Dictionary resides in and after inspection it contains the class I want to reference. So I know that 1. the dll is in the right place to be accessed and is in references. 2. The dll contains the data I want.

Here are some bits of code for the Resource Dictionary

The listing of the namespace

xmlns:modulemodel="clr-namespace:Company.Project.Module.Folder;assembly=Company.Project.Module"

Creating the resource to be referenced

<modulemodel:ModelBindings x:Key="ModuleModelBindings"/>

Like the other people's errors the intellisense says its kosher. ALso the xmlns listing was created with intellisense's autocomplete and retyped manually. Neither worked.

I also tried moving everything to app.xaml and it still gave me the same error.

If I remove the body of the ResourceDictionary file the code compiles fine, but all the bindings are broken.

Lastly, all the resource definitions used to be defined within the xaml files where they were used, that worked fine. Its only after I tried creating them from a different project that it didn't work. I changed this to fix an error and going back to the old method could potentially be problematic.

Edit: Here is the best I can do in terms of showing the resource dictionary I am using

<SharedResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:modulemodel="clr-namespace:Company.Project.Module.Folder;assembly=Company.Project.Module"
                    >
    <modulemodel:ModelBindings x:Key="ModuleModelBindings"/>
    
</SharedResourceDictionary>

if I replace SharedResourceDictionary with ResourceDictionary the same error occurs.

app.xaml and the SharedResourceDictionary above are comparetively in the namespace Company.Project.Main and it has references to both where SharedResourceDictionary is defined as well as the different module projects I put into the code above

Trochaic answered 22/7, 2011 at 18:29 Comment(0)
T
19

Looks like it was mostly a user error. But this could happen to others. When I copied the xmlns:moduleviewmodel definition from its original file I had to add the assembly= portion on my own. Like I said I both did it myself as well as use the autocomplete the follows from typing 'xmlns:moduleviewmodel=' . Right before we found the error we tried the autocomplete again because we found that there was one of the 7 namespaces not generating the error. It was then that I noticed that there was a letter in assembly path that was not capitalized that should be. The weird thing is the autocomplete actually inserts this error on its own. While we were compiling that I noticed the erroneous letter. The weirder thing is that after I fixed all the paths manually we tried the autocomplete again and it spelled it correctly.

I have no idea the cause of the errored autocomplete but with the fixed letter it compiles just fine.

Now I just wonder if anyone will believe the autocomplete was changing up on me!

Trochaic answered 25/7, 2011 at 12:40 Comment(0)
M
45

According to this article, you just do as follow:

FROM:

xmlns:ZZZ="clr-namespace:YYY;assembly=YYY"

TO:

xmlns:ZZZ="clr-namespace:YYY;assembly="

leave empty value for assembly=

This is the solution that works for me.

Manasseh answered 5/3, 2014 at 4:37 Comment(3)
Remove the entire 'assembly=' :)Microreader
It is invalid markup so you can't even see it until you runTubuliflorous
Thank you, this solved an issue for me when I moved a reference from another assembly to the same as the XAML file. I don't understand why you can't explicitly reference yourself in the assembly, but that was the resolution for me!Derail
P
30

This may not be the solution for your problem, but I see the error you are asking about quite often, and the issue is generally caused by a problem loading the assembly.

If you check your assemble, and it has a yellow triangle attached to it, then it is likely not compatible with your current project setup, due do different versions of .NET, or something of the sort.

This will usually fail silently, or only cause a warning; when you try to reference the assemble in your XAML you will get an error like you described.

Pyralid answered 27/1, 2017 at 22:38 Comment(0)
T
19

Looks like it was mostly a user error. But this could happen to others. When I copied the xmlns:moduleviewmodel definition from its original file I had to add the assembly= portion on my own. Like I said I both did it myself as well as use the autocomplete the follows from typing 'xmlns:moduleviewmodel=' . Right before we found the error we tried the autocomplete again because we found that there was one of the 7 namespaces not generating the error. It was then that I noticed that there was a letter in assembly path that was not capitalized that should be. The weird thing is the autocomplete actually inserts this error on its own. While we were compiling that I noticed the erroneous letter. The weirder thing is that after I fixed all the paths manually we tried the autocomplete again and it spelled it correctly.

I have no idea the cause of the errored autocomplete but with the fixed letter it compiles just fine.

Now I just wonder if anyone will believe the autocomplete was changing up on me!

Trochaic answered 25/7, 2011 at 12:40 Comment(0)
P
5

Check Warnings in error list, in my case there where messages about unresolved .Net 4.5.1 references, while my project target framework was 4.5

Processional answered 15/1, 2018 at 15:29 Comment(0)
W
4

If you have user control in same assembly as WPF form make sure you get rid of assembly part while importing namespace

Wrong Import: xmlns:usercontrol="clr-namespace:CCFARKS.UserControls;assembly=CCFARKS"

Corret: xmlns:usercontrol="clr-namespace:CCFARKS.UserControls"

Wipe answered 30/11, 2018 at 15:17 Comment(0)
M
3

I had this error while using a UserControl inside another one in a .net 7 wpf library project. For me removing $(MSBuildProjectName) from the .csproj file was the only solution that worked.

Mesmerize answered 27/5, 2023 at 17:29 Comment(1)
This is a known bug: github.com/dotnet/wpf/issues/5711Peripteral
I
2

I have had a totally different reason for this error:

I was trying to use a class from assembly A, so I

1) added reference to this assembly to my project,

2) added reference to assembly B, which is used by assembly A, to my project,

3) added to my XAML

 xmlns:assemblyA="clr-namespace:A;assembly=A"

3) added to my code

using A;

This didn't work, I have got this "Tag doesn't exist" error.

What did help, was adding

using B;

in my code, though I do not use directly anything from assembly B.

Irremeable answered 30/12, 2014 at 12:34 Comment(0)
D
1

it's an old question but, the problem comes from the .csproj. Be sure the "page" element is defined before the "compile" element in the "itemgroup" section.

Good :

  <ItemGroup>
...
<Page Include="ScreenComponents\StatusBar.xaml">
  <SubType>Designer</SubType>
  <Generator>MSBuild:Compile</Generator>
</Page>
<Compile Include="ScreenComponents\StatusBar.xaml.cs">
  <DependentUpon>StatusBar.xaml</DependentUpon>
</Compile>
…

Not good :

  <ItemGroup>
...
<Compile Include="ScreenComponents\StatusBar.xaml.cs">
  <DependentUpon>StatusBar.xaml</DependentUpon>
</Compile>
<Page Include="ScreenComponents\StatusBar.xaml">
  <SubType>Designer</SubType>
  <Generator>MSBuild:Compile</Generator>
</Page>
…

regards,

Descend answered 25/10, 2019 at 10:19 Comment(0)
O
0

This may happen if you have errors other than this specific error also. More errors may cause the file not to compile properly and resulting in this error.

First try to remove other build 'ERRORS' and 'WARNINGS' also. Then rebuild the solution.

Orten answered 2/2, 2022 at 6:13 Comment(0)
K
0

In my case the project file was missing the RootNamespace element. Not sure why it was missing but I had the same exact error, and adding it manually fixed the issue.

<RootNamespace>YourNamespace</RootNamespace>
Kosygin answered 20/10, 2023 at 10:31 Comment(0)
H
0

In my case, the solution is to add the assembly name explictly in the csproj file:

<AssemblyName>YourAssembllyName</AssemblyName>
Helicon answered 13/11, 2023 at 3:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.