The name does not exist in the namespace error in XAML
Solution 1
When you are writing your wpf code and VS tell that "The name ABCDE does not exist in the namespace clr-namespace:ABC". But you can totally build your project successfully, there is only a small inconvenience because you can not see the UI designing (or just want to clean the code).
Try to do these:
In VS, right click on your Solution -> Properties -> Configuration Properties
A new dialog is opened, try to change the project configurations from Debug to Release or vice versa.
After that, re-build your solution. It can solve your problem.
Solution 2
If the assembly is different from the namespace in which your class is contained, you have to specfiy it explicitly.
ex:-
xmlns:Local="clr-namespace:MusicPlayer.Controls;assembly=MusicPlayer"
Solution 3
In my case it was because of other compile errors. When other errors have been solved this seemingly related error was also removed from the list. Specially the errors at the bottom of the errors list and on pages you have recently changed.
So do not pay attention to this error directly and focus on other errors at first.
Solution 4
I've seen this issue go away by clearing the Xaml Design Shadow Cache. I had the issue with Visual Studio 2015 Update 1.
In Visual Studio 2015 the Cache is located here:
%localappdata%\Microsoft\VisualStudio\14.0\Designer\ShadowCache
Process:
- Right-Click on the solution in the Solution Explorer and Choose "Clean Solution"
- Shutdown Visual Studio
- Delete the ShadowCache folder
- Reopened the Visual Studio project
- Rebuild the solution
And voila no more namespace errors.
Solution 5
Try changing the build target platform to x86 and building the project.
I noticed via Subversion that I apparently changed the project build Platform target to x64. This was the only change I had made. After making that change, the code was working for a short while before it started showing the same error you experienced. I changed the platform target to x86 to test and suddenly my designer was working again. Subsequently, I changed it back to x64, and the problem has disappeared completely. I suspect that the designer builds some kind of cached code in x32 and changing the x64 build platform breaks it when you make code changes.
Related videos on Youtube
Jeff Davis
Updated on July 08, 2022Comments
-
Jeff Davis almost 2 years
Using VS2012 working on a VB.NET WPF application. I have a simple MusicPlayer tutorial app I am using to learn WPF. I am converting a C# version of the tutorial to VB.NET step by step.
It has 2 classes in the app that are both under the same namespace. I am able to reference the namespace in the XAML but when I try to reference the class object in XAML I get an error and I am not able to compile.
Strange thing is that the IntelliSense works fine with both referencing the namespace via the xmlns:c= tag and also when typing the class object using
<c:
But the object is underlined and errors are generated trying to build or work in the designer.The .vb class files are in a folder called \Controls. The Main project Root Namespace is intentionaly left blank. The class is coded like this...
Namespace MusicPlayer.Controls Public Class UpdatingMediaElement .... code here End Public End Namespace
The xaml looks like this
(namespace defined in the
<Window >
tagxmlns:c="clr-namespace:MusicPlayer.Controls"
(object defined in a
<Grid>
)<c:UpdatingMediaElement Name="MyMediaElement" />
(error displayed) The name "UpdatingMediaElement" does not exist in the namespace "clr-namespace:MusicPlayer.Controls".
Not sure what is wrong or how to fix it?
-
Falaque about 8 yearsRestarting the visual worked for me. (never underestimate the power of restarting)
-
Borzh almost 7 yearsA little help for those who are struggling with this: make sure your class is public.
-
b.holz over 3 yearsclose the xaml document while starting/building the app
-
Emir about 3 yearsJust like Falaque said, restarting helps in many cases. In my case that was deleting my repository and cloning it again. This way you make sure that even those git-ignored files are deleted.
-
-
HK1 about 10 yearsNote that doing a build/compile resolved this problem for me, even though I didn't have any other unrelated compile errors. Looks like the XAML windows aren't always aware of new classes until you've done a compile.
-
Bouke about 10 yearsWhile it appeared to have solved my problem at first, it still throws the same error. However, now I'm even not able to build the solution anymore.
-
Vasanth Sriram almost 10 years@bouke Clean the solution and rebuild it
-
teynon over 9 yearsI've had this re-occur and I can confirm this solves the problem for me. You can switch back to x64 after you build it in x86.
-
bic about 9 yearsThis worked for me as well but I also had to restart VS to clear the error list? Weird.
-
Bryan Greenway about 9 yearsThis worked for me too in VS 2012...after hours of trying to figure out something logical. Thanks, Tom!
-
Grault over 8 yearsSwitching to x86 and back to x64 fixed the problem here, so thanks for inspiring me to try that. I had even closed VS, deleted bin and obj, and rebuilt, along with other suggestions, and nothing helped until this.
-
Simon Smith about 8 yearsThis still happens in Visual Studio 2015 Update 1. Your solution worked - thanks!
-
Keith about 8 yearsAwesome, thanx. That really helped
-
Mario Tacke about 8 yearsThis was the case for me, I moved it to my vm (on which I develop) and boom no problems. Thanks!
-
SezMe about 8 yearsIN VS 2015 Update 2 there is no Configuration Properties under Solution->Properties.
-
SezMe about 8 yearsYes, this also worked for me on VS2015 Update 2. However, it was necessary for me to reload my external dll files and rebuild them also.
-
DaleyKD about 8 yearsWith VS2015U2, I still get this issue in x64. Works great in Any CPU. Switching back and forth doesn't work for me.
-
ketura almost 8 yearsPerhaps not, but I found that simply switching between Debug and Release mode on the toolbar worked regardless.
-
Khale_Kitha over 7 yearsSadly, didn't change a thing, for me. Still dealing with this annoying after almost a whole year. :/
-
Ocab19 over 7 yearsThanks! This ended up working for me. It's sad to see this tricks still being necessary in VS15
-
Lance over 7 years@ketura - yes it worked for me too. I changed it from debug to release, build the solution then checnge it back to debug then error's gone.
-
ckittel over 7 yearsThis was the case for me as well it appears. Moving them to being on a local drive (instead of a network share -- as set up by Parallels to union both the Mac and Windows filesystem a bit), fixed the issue.
-
Mathieu Guindon over 7 yearsOr, right-click solution > "Clean Solution"; right-click solution again > "Rebuild". Done.
-
MissingNumber over 7 yearsAmazing ..:) Worked for me on VS15
-
SERWare about 7 yearsThis was the best advise for me, but as @HK1 sometimes there's no other entries in the compiler error list... there aren't errors in the list but there are other errors. To see them, comment or delete the lines marked with the namespace error, compile again and then you will see the other compiler errors. Amend them, and the lines before marked with the namespace error will ok when you restore them.
-
Tedd Hansen almost 7 yearsConfirmed on VS 2017 version 15.2 (26430.15) in July 2017. Simply changed in dropdown from Debug to Release, compiled and error was gone, changed back and compiled and error was still gone.
-
Alan Wayne almost 7 yearsIn addition to the above, I had to switch between x64 and x86 in Visual Studio 2015. Also, pay attention to the Zoom setting (for some reason mine got set to 3.57%, so even after a correct compilation the XAML did not show up).
-
Ehsan Iran-Nejad over 6 yearsIt also helps to open the solution through a mapped drive. If I open my solution with a UNC path it can not find the namespaces correctly. (Using VS Pro 2017)
-
Maxence over 6 yearsYou can use %localappdata%\Microsoft\VisualStudio\14.0\Designer\ to go immediately to the right folder
-
geometrikal over 6 yearsThis worked for me - I had downloaded a project off of dropbox and was getting the error. I also had to delete the ShadowCache
-
dovid over 6 years(needed and) work also in VS2017, microsoft have to put it in official documentation :)
-
bokibeg over 6 yearsIt seems that VS17 is especially stubborn - Tried changing Rel/Dbg, changing x64/x86, deleted ShadowCache, ComponentCache, Bin/Obj folders, still have "errors" and designer doesn't work for this one very small app (other apps with like 50 WPF views work fine). Happened suddenly and can't go away. Had this prob before many times but first time on VS17 and can't fix it now. Still tho this is best answer as it worked so many times before.
-
LordWilmore over 6 yearsYour suggestion is a significant change that may not even be a possibility for the OP if they are targeting a particular environment. Either way it is very unlikely to be the cause of the problem, and if it solved the issue for you then I would suggest that your actual problem was mismatching project configurations, which would have manifested itself in many different ways to the problem shown here.
-
pdschuller about 6 yearsThis answer is supplied at least twice above.
-
Ryan about 6 yearsWorked with VS2017 15.6.7
-
Mathieu Guindon about 6 yearsI love how I come back to this answer, and I've already upvoted it, ...2.5 years ago.
-
Nasenbaer almost 6 yearsWorked. Changed project file from
<PlatformTarget>x64</PlatformTarget>
to<PlatformTarget>AnyCPU</PlatformTarget>
-
Dick over 5 yearsAnd it still occurs in VS 2017 15.7 (August 2018). I've long given up the hope that the VS development team is actually able to really improve this product at all. For me I had to put it back from ARM to x86 mode but the trick as about the same as Toan wrote.
-
RudolfJan over 5 yearsSame issue. Switching to release makes the issue dissappear, but then back to debug makes it come back. Looks like it is an IDE issue which does probably not affect the code. I guess I will file an issue as well.
-
Dustin_00 over 5 yearsHit this in VS 2017 and found another thing to try to fix it. In your library references, go delete your xmlns:control ="clr-namespace:BadApp.BadLibrary", build, re-add the line, build, and that fixed it for me (after I'd tried the changing target build to Release and Debug trick).
-
Jonathan Alfaro over 5 yearsThis did it for me. The weird thing is that the converters were in the same assembly as the xaml file.... But they were on a different namespace.
-
MattE about 5 yearsWorked for me in VS 2017 after I changed it back and forth twice
-
Teneko about 5 yearsThanks, the assembly was missing.
-
Paul McCarthy about 5 yearsHaving a designer that only works if you build the solution is terrible. Imagine telling a car designer to build the whole car before seeing the design.
-
Jesse Roper almost 5 yearsVisual Studio 2019 - i commented out all code that referenced the file in this namespace. Built solution successfully. Uncommented code and it works.
-
Greg K. almost 5 yearsVS 2019. This shit just happened to me I've tried everything. commenting out/in rebulding, restarting, cleaning the solution, deleting the .suo files. Nothing works. I have literally EXACTLY the same datatemplates for other classes and it works perfectly. Just for three classes this doesn't work at all....
-
icernos almost 5 yearsIn other words, project's .NET Framework version can't be older than referenced project's .NET Framework version.
-
Mystic Lin over 4 yearsWorked for me in VS 2017, I just switched to Release, didn't rebuild solution.
-
user3953989 over 4 yearsVS2019 net core 3 wpf, just switching the drop down from Debug to Release fixed it for me... smh...
-
YarsRevenge13 about 4 yearsI had removed a method in code behind that was still referenced in XAML. Once I removed the reference, this error went away.
-
mike00 over 3 years@GregK. I have exactly the same. VS 2019 and tried every hint already. Nothing fixes that.
-
Abdelkrim Tabet Aoul over 3 yearsyes, Rebuild will solve most of problems because xaml tried to call an element that is not build yet. Rebuild every time you create a new class and try to use it on xaml
-
nduru over 3 yearsThis has worked for me, the real errors are often hiding, even after clean and rebuild. The errors can lurk in unopened Xaml files, make sure you open all of them.
-
Ola Berntsson over 3 yearsLatest VS2019; no amount of cleaning/rebuilding would fix this but toggling between Debug/Release magically solved it. WPF is a burning pile of trash.
-
Abdullah Tahan over 3 yearsI found a hint which really helped me out reducing the errors appear at "error list" tab on top left drop down list select "open documents" so it will show you only the errors from the open docs , i go the the uncommitted changes and open all the files so i know that only few of those files is broke the entire solution
-
z33k almost 3 yearsGood piece of advice. Thx. It hasn't solved the problem all by itself but helped me find a solution as it cut the number of compile errors from 190 to 5.
-
z33k almost 3 yearsDon't want to add to the pile so just for somebody who will stumble here: in my case it was a shadowing namespace in XAML. I had one namespace, used a user control from it and then on another line in namespace declarations I had another one mapping the same ns to a different name. Thus it shadowed the former and then all hell broke loose.
-
Pharaz Fadaei over 2 years"there is only a small inconvenience" sometimes it's not that small. Seeing a bunch of fake errors makes it so hard to find the real errors that prevent building the project.
-
CiucaS about 2 yearsI can still reproduce this in VS2022. Hard to believe they could not fix this in 8 years...