Name does not exist in namespace error in XAML

Using VS2012 working on a VB.NET WPF application. I have a simple MusicPlayer tutorial application that I use to learn WPF. I am converting the C # version of the tutorial to VB.NET step by step.

There are 2 classes in the application that are under the same namespace. I can reference the namespace in XAML, but when I try to reference the class object in XAML, I get an error message and I cannot compile it.

The strange thing is that IntelliSense works fine with a link to the namespace via the xmlns: c = tag, as well as when entering a class object using <c: But the object is underlined and errors are generated, trying to build or work in the designer.

Class .vb files are located in a folder named \ Controls. The main root space of the project intentionally remains empty. The class is encoded as follows:

 Namespace MusicPlayer.Controls Public Class UpdatingMediaElement .... code here End Public End Namespace 

xaml is as follows

(namespace defined in the <Window >

 xmlns:c="clr-namespace:MusicPlayer.Controls" 

(object defined in <Grid> )

  <c:UpdatingMediaElement Name="MyMediaElement" /> 

(error displayed) The name "UpdatingMediaElement" does not exist in the namespace "clr-namespace: MusicPlayer.Controls".

Do not know what is wrong or how to fix it?

+108
wpf visual-studio-2012 xaml
Feb 02 '13 at 19:40
source share
33 answers
  • one
  • 2

When you write your wpf and VS code, say “the name ABCDE does not exist in the clr-namespace: ABC namespace”. But you can completely build your project successfully, there is only a slight inconvenience, because you cannot see the user interface design (or just want to clear the code).

Try to do this:

  • In VS, right click your solution -> Properties -> Configuration Properties

  • A new dialog box opens, try changing the project configuration from Debug to Release or vice versa.

Then rebuild your decision. He can solve your problem.

+203
Aug 01 '14 at 11:07
source share

If the assembly is different from the namespace that contains your class, you must explicitly specify it.

eg: -

 xmlns:Local="clr-namespace:MusicPlayer.Controls;assembly=MusicPlayer" 
+49
Apr 01 '13 at
source share

I saw this issue go away by clearing the Xaml Design Shadow Cache. I had a problem with Visual Studio 2015 Update 1.

In Visual Studio 2015, the cache is here:

 %localappdata%\Microsoft\VisualStudio\14.0\Designer\ShadowCache 

Process:

  1. Right-click the solution in Solution Explorer and select Clean Solution.
  2. Visual Studio Shutdown
  3. Delete ShadowCache folder
  4. Opened Visual Studio Project
  5. Restore solution

And voila, there are no more namespace errors.

+26
Mar 03 '16 at 18:44
source share

Try changing the target build platform to x86 and create a project.

I noticed through Subversion that I apparently changed the purpose of building the platform for the x64 platform. That was the only change I made. After making this change, the code did not work for long before it started showing the same error that you encountered. I changed the purpose of the platform to x86 for testing, and suddenly my designer worked again. Subsequently, I changed it to x64 and the problem completely disappeared. I suspect that the designer is creating some cached code in x32, and changing the x64 build platform breaks it when you make changes to the code.

+23
Dec 26 '14 at 10:00
source share

In my case, it was due to other compilation errors . When other errors were resolved, this seemingly related error was also removed from the list. Especially errors at the bottom of the error list and on pages that you recently changed.

Therefore, do not pay attention to this error directly and focus on other errors first .

+21
May 28 '13 at 9:48
source share

I don't know if this will help anyone else

I am new to WPF and still new to VB.net - so I assumed that getting this error was due to the fact that I was making a summit stupid ........ suppose I was really! I managed to get rid of it by moving my project from a shared drive to one of my local drives. The error has disappeared, the project does not compile absolutely no additional problems. It looks like VS2015 still has problems with projects stored on a shared drive.

+7
Mar 14 '16 at 18:12
source share

Perhaps another solution to compile the project, but the XAML error:

  • In the solution, examine the node project containing xaml
  • Right-click the project and select Upload Project
  • Right-click on the project and select "Update Project". Make sure your project is still selected as the "Startup Project". If not:
  • Right-click on the project and select "Make As Launch Project"

No need to rebuild or close the visual studio.

+5
Mar 24 '17 at 14:33
source share

Jesus ... This is still a problem five years later in Visual Studio 2017. Since I am new to WPF, I was sure that the problem was something to me, but no, everything compiled and worked correctly.

I tried to restore, clean and rebuild, switch between x86 / x64 output, restart Windows, clear the ShadowCache folder by adding "; assembly = {my main assembly name}" to the XML namespace declaration, nothing worked! The only thing that did:

Put my static class of commands (in my case it was about the design to detect my WPF commands) in a separate assembly and instead changed the name of the assembly.

+3
Dec 15 '17 at 9:36 on
source share

I had the same problem, and in my case, Markup Design View asked me to rebuild the solution and did not show me the layout of the form with this message: Design view is unavailable for x64 and ARM target platforms or Build the Project to update Design view .

It cannot be solved by restoring the solution (neither the design nor the error "Name does not exist in the namespace")

I think this was because I was playing with the settings in Solution -> Properties> Configuration Properties

Finally, I solved the problem with two tasks:

  • Checking all the checkboxes in the assembly column on the page: Solution → Properties → Configuration Properties
  • Change solution configurations from Debug to Release or vice versa.

I think this is a bug in Visual Studio2012 Update 2.

+2
Jun 02 '13 at 13:55 on
source share

The same problem affects Visual Studios 2013, Service Pack 4. I also tried this with a preview of Visual Studios 2015 with the same results.

This is simply a limitation of the WPF visualizer that the Visual Studios team has not fixed. As proof, building in x86 mode allows the visualizer and building in x64 mode to disable it.

Oddly enough, intellisense works for Visual Studios 2013, Service Pack 4.

+2
Jan 15 '15 at 23:24
source share

I had this problem recently using VS 2015 Update 3 for my WPF project in .NET 4.6.2. A copy of my project was in a network folder , I moved it locally and solved the problem.

This can solve other problems, since it seems that VS 2015 does not like network paths. Another problem, which is a big problem for them, is the synchronization of git repositories, if my project is in a network path, is also solved by moving it locally.

+2
Sep 28 '16 at 10:37
source share

Try to check assembly links. If you have a yellow exclamation mark in the links to the project, there is a problem, and you will get all kinds of errors.

If you know that the project link is correct, check the Target structure. For example, having a project using a link to version 4.5, a project with a frame of 4.5.2 is not a good combination.

+1
Jul 22 '16 at 7:44
source share

It seems that this problem can be solved using various "tricks".

In my case, I built / restored / cleaned the whole solution, and not just the project that I worked on as part of the solution. As soon as I clicked "Build [my project]", the error message disappeared.

+1
Jul 25 '16 at 23:40
source share

The solution for me was to unlock the prefabricated DLLs. The error messages you received do not indicate this, but the XAML designer refuses to download what he calls "isolated" assemblies. You can see this in the output window when creating. DLLs are blocked if they are downloaded from the Internet. To unlock your third-party DLL files:

  • Right-click the DLL file in Windows Explorer and select Properties.
  • At the bottom of the General tab, click the Unblock button, or select the check box.

Note. Only unlock the DLL if you are sure that they are safe.

+1
Feb 21 '17 at 15:15
source share

In my case, the user control was added to the main project. I have tried various solutions above, but to no avail. Either I get Invalid Markup, but the solution will compile and work, or I would add xmlns: c = "clr-namespace: MyProject; assembly = MyProject", and then the markup would be displayed, but I would get a compilation error that does not exist in XML namespace.

Finally, I added a new WPF User Control Library project to the solution and moved my user control from the main project to this one. Added a link and changed the assembly to point to a new library, and finally, the markup worked, and the project was compiled without errors.

+1
Apr 03 '17 at 15:59
source share

I went through all the answers and no one helped me. Finally, I was able to solve this myself, so I present the answer, since it can help others.

In my case, the solution had two projects, one of which contained models (for example, the name of the project and assembly was Models ), and the other - models of views and views (according to our convention: the project, assembly name and namespace were Models.Monitor by default) . The Models.Monitor project refers to models.

In the Models.Monitor project in one of xaml, I included the following namespace: XMLNS: monitor = "CLR names: Models.Monitor"

I suspect that MsBuild and Visual Studio were wrong because they tried to find the type “Monitor” in the “Models” assembly . To solve the problem, I tried the following:

None of the above worked.

Finally, I gave up, and when the work around moved UserControl, I tried to use it in another namespace: 'ModelsMonitor' . After that I was able to compile.

+1
Jun 02 '17 at 19:07 on
source share

In my case, the problem was due to some phantom files in the obj project directory. The following fixed the problem for me:

  • Clean project
  • VS output
  • rm -rf / obj / *
  • Call VS and restore
+1
Apr 30 '19 at 20:30
source share

VB.NET does not automatically add namespace information based on folder structure, as is done in C #. I think I'm moving on to the same tutorial as you (Teach Yourself WPF in 24 hours), and doing the same conversion to VB.

I found that you need to manually add namespace information in the AND XAML class and XAML.VB code to use the namespace as described in the book. Even then, VB does not automatically assign the namespace to the Assembly, as in VB.

Here is another article that shows how to include this in your project templates to automatically create namespace information - Automatically add a namespace when adding a new p> element

0
Sep 30 '13 at 14:57
source share

On the solution properties page, check the assembly platform that contains the "UpdatingMediaElement" and the assmeblies that contain any of the superclasses and interfaces of which the "UpdatingMediaElement" subclasses or implements. It seems that the platform of all these assemblies should be "AnyCPU".

0
Sep 14 '14 at
source share

Another possible reason: the post-build event removes the project DLL from the build folder.

To clarify: a WPF designer can say: "The name XXX does not exist in the namespace ..." even if the name exists in the namespace and the project builds and works very well if the post-build event removes the project DLL from the build folder (bin \ Debug, bin \ Release, etc.). In Visual Studio 2015, I have personal experience.

0
Feb 15 '16 at 20:12
source share

Good, so none of these tips worked for me, unfortunately. In the end, I was able to solve this problem. Visual Studio doesn't seem to play well with network drives. I solved this problem by moving the project from a shared drive to a local and recompiled one. More bugs.

0
Jul 28 '16 at 18:46
source share

Adding to the heap.

Mine was the build name of the WPF application, it was the same build name as the reference dll. Therefore, make sure that you do not have duplicate assembly names in any of your projects.

0
Mar 01 '17 at 18:10
source share

I had a solution stored in a network resource, and every time I opened it, I received a warning about untrusted sources. I moved it to a local drive, and the "namespace does not exist" error also disappeared.

0
May 10 '17 at 10:05 p.m.
source share

Also try right-clicking on the project-> properties and change the target platform to Any CPU and rebuild, then it will work. It worked for me

0
Feb 16 '18 at 12:40
source share

In my case, the namespace and class were written the same, so for example, one of my namespaces was

 firstDepth.secondDepth.Fubar 

which contains its own classes (e.g. firstDepth.secondDepth.Fubar.someclass)

but I also had a class ' Fubar ' in the namespace

 firstDepth.secondDepth 

which is textually resolved in the same way as the Fubar namespace above.

Do not do this

0
Oct 10 '18 at 18:06
source share

I also have a lot of problems with this! Intellisense helps me fill out the namespace and everything else, but the compiler is crying. I tried everything that I found in this and other topics. However, in my case, what helped in the end was to write something like this: xmlns: util = "clr-namespace: LiveSpielTool.Utils; assembly ="

Leaving the assembly name blank. I have no idea why. But it was mentioned here. I must add that I am developing the assembly, so the assembly attribute may make sense. But entering the assembly name did not work. So weird.

0
Nov 26 '18 at 12:10
source share

This problem can also be caused by the fact that the assembly you are referencing is not actually assembled. For example, if your xaml is in Assembly1 and you refer to the class also in Assembly1, but this assembly contains errors and does not create, this error will be shown.

I feel stupid about this, but in my case I was breaking the user control and as a result had all kinds of errors in related classes. Since I tried to fix them all, I started with the errors in question, not realizing that xaml relies on built-in assemblies to find these links (as opposed to C # / vb code that can solve it even before you build it).

0
Dec 14 '18 at 0:21
source share

I added the added assembly as a project - first I deleted the ddl that was added specifically to the dll links - which did it.

0
Jan 25 '19 at 21:08
source share

I constantly run into this problem. My views are in the WPF user control library project (a variant of the class library). I can refer to pre-built assemblies, but I cannot refer to any code in another project of the same solution. As soon as I move the code to the same project as the recognized xaml.

0
Mar 12 '19 at 16:53
source share

In my case, this problem will occur when the architecture of the wpf program does not exactly match the dependency. Suppose you have one x64 dependency and the other is AnyCPU. Then, if you select x64, the type in the AnyCPU dll will not exist, otherwise the type in the x64 dll will not exist. You simply cannot imitate both of them.

0
May 09 '19 at 8:10 am
source share
  • one
  • 2



All Articles