the name ... does not exist in the namespace clr-namespace ...
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The XAML error The name "X" does not exist in the namespace "clr-namespace:Y" occurs in WPF, UWP, MAUI, and Xamarin applications when the XAML parser cannot find a type referenced in a clr-namespace declaration. This is a build-time error that prevents the designer from rendering and the application from compiling. The root cause is usually a mismatch between the namespace declaration in XAML and the actual C# namespace/class.
The Error
In XAML, you reference C# types via clr-namespace:
Common Causes and Fixes
1. Class Is Not Public
The referenced class must be public, not internal (the default for classes without an access modifier):
2. Namespace Mismatch
The clr-namespace in XAML must exactly match the C# namespace:
3. Project Not Built
The XAML designer resolves types from the compiled assembly. If you just added a new class, you must build the project before the XAML designer can find it:
4. Different Assembly
If the class is in a different project/assembly, you must specify the assembly name:
The assembly parameter must match the assembly name (not the project name or namespace):
5. Spaces in the clr-namespace Declaration
The clr-namespace URI must not contain spaces:
6. Target Framework Mismatch
If the referenced assembly targets a different framework, types may not resolve:
Ensure both projects target compatible frameworks (e.g., both .NET 8, or .NET Standard 2.0 for the library).
7. Conditional Compilation
Types inside #if directives may not be available in all build configurations:
Step-by-Step Debugging
Step 1: Verify the Class Exists and Is Public
Step 2: Build the Project
Step 3: Check XAML Namespace Declaration
Step 4: Restart Visual Studio
The XAML designer cache can become stale. Close and reopen Visual Studio, or:
- Delete the
.vsfolder - Delete
binandobjdirectories - Rebuild
WPF vs MAUI vs Xamarin Differences
| Platform | Namespace Format | Notes |
| WPF | clr-namespace:Ns;assembly=Asm | Standard format |
| MAUI | clr-namespace:Ns or xmlns:local="..." | Also supports x:DataType |
| Xamarin.Forms | clr-namespace:Ns;assembly=Asm | Assembly required for external |
| UWP | using:Ns | Different syntax entirely |
UWP/WinUI Syntax
UWP uses using: instead of clr-namespace::
Common Pitfalls
- Designer vs runtime: Sometimes the designer shows the error but the project compiles and runs fine. This is a designer cache issue — rebuild and restart Visual Studio.
- Partial classes: If your control uses a partial class (e.g., code-behind for XAML), ensure both parts are in the same namespace.
- NuGet package classes: For types from NuGet packages, use the package's documented namespace and assembly name, not what you think they might be.
- Refactoring namespace changes: If you rename a namespace in C#, XAML files are not automatically updated. Use a global find-and-replace to update all
clr-namespace:references. - Generic types: Generic types like
MyControl<T>cannot be directly used in XAML. Create a non-generic derived class instead.
Summary
- Verify the class is
publicand the C# namespace exactly matches theclr-namespacein XAML - For types in other assemblies, add
;assembly=AssemblyName(no spaces) - Build the project after adding new classes — the designer needs a compiled assembly
- Clean and rebuild if the error persists (
rm -rf bin/ obj/ .vs/) - UWP uses
using:Namespaceinstead ofclr-namespace:Namespace
Related reading
- The name 'ConfigurationManager' does not exist in the current context
- The reference assemblies for framework .NETFramework,Versionv4.6.2 were not found
- The SqlParameter is already contained by another SqlParameterCollection - Does using cheat?
- The State of Linkers for .NET apps aka Please Sir, May I have a Linker 2009 edition
- The operation is not valid for the state of the transaction error and transaction scope
- The pipe 'async' could not be found
- The type is defined in an assembly that is not referenced, how to find the cause?
- The type or namespace name 'Entity' does not exist in the namespace 'System.Data

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.