XAML compile error: The tag '{0}' does not exist in XML namespace '{1}'

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Summary: When a library implements an interface from another library that requires an assembly, creating an instance of this class in XAML throws an error that it does not exist in XML namespace.
There had been similar threads to this but there was no answer to fix the issue.
<br/>
<br/>
To reproduce:<br/>
<br/>

<ol>
Create new Silverlight Class Library "ClassA" Add a reference to .NET assembly: "System.Json" (Copy To Local = False, Specific Version = False)
Add an interface that use this assembly (for example):
<div style="color:black; background-color:white
<pre> <span style="color:blue public <span style="color:blue interface IJson
{
<span style="color:blue void FromJson(JsonObject json);
JsonObject ToJson();
}
[/code]

Add another Silverlight Class Library "ClassB" to implement the interface. Add an empty public constructor to allow creating an instance in XAML. Add a reference to .NET assembly: "System.Json" (Copy To Local = False, Specific Version = False)
Add a reference to project "ClassA" Add a Silverlight Application that will use ClassB in XAML. Add a reference to projects "ClassA" and "ClassB" Add the following code to MainPage.xaml
<div style="color:black; background-color:white
<pre> xmlns:b="clr-namespace:ClassB;assembly=ClassB"
xmlns:a="clr-namespace:ClassA;assembly=ClassA
<span style="color:blue <<span style="color:#a31515 Grid <span style="color:red x:Name<span style="color:blue =<span style="color:black "<span style="color:blue LayoutRoot<span style="color:black " <span style="color:red Background<span style="color:blue =<span style="color:black "<span style="color:blue White<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 ListBox<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 b<span style="color:blue :<span style="color:#a31515 Class1<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 ListBox<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Grid<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 UserControl<span style="color:blue >
[/code]

Build the solution. Notice XAML-compile error: The tag Class1 does not exist in XML namespace clr-namespace:ClassB;assembly=ClassB
</ol>
<br/>
This error goes away when reference to "System.Json" is added to the Silverlight Application or reference to projects ClassA and ClassB are removed and added again.
<br/>
<br/>
The issue is the XAML compile error is misleading and is not descriptive of what could really be wrong. If required assemblies need to be referenced in the project, this error does not indicate it.
<br/>
<
Jennifer Nery<br/>

View the full article
 
Back
Top