The name "XYZ" does not exist in the namespace "clr-namespace: ABC"

I worked on creating markup extensions and started getting very strange VS behaviors. I extracted and identified the problem in a separate solution. The problem is that VS cannot create a CLR object in XAML.

There he is:

View:

<Window x:Class="WpfApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wpfApplication4="clr-namespace:WpfApplication4"> <Window.Resources> <wpfApplication4:Dog x:Key="doggy" /> </Window.Resources> <Grid /> </Window> 

Code behind:

 using System.Windows; namespace WpfApplication4 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } } } 

Dog Class:

 namespace WpfApplication4 { public class Dog { } } 

App.Xaml (no code in App.Xaml.cs):

 <Application x:Class="WpfApplication4.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> </Application.Resources> </Application> 

Project settings

The exception I get is:

 Error 1 The name "Dog" does not exist in the namespace "clr-namespace:WpfApplication4". \\hopr1\folders$\vxk\Documents\Visual Studio 2012\Projects\WpfApplication4\MainWindow.xaml 6 9 WpfApplication4 

I can run the solution, but the designer fails with the error "Invalid Markup" Any ideas?

Edit

I am launching VS 2012 Update 2 The same solution works in VS 2012 Update 1

+63
c # wpf xaml
Apr 25 '13 at 13:54
source share
21 answers

Your solution works on a network resource..Net (and Visual Studio) can work on permission / access when working on a network resource.

Copy the solution to the local drive (with full trust) and everything will be fine.

You can get a network drive with full confidence - you can find the answers to this in StackOverflow and other places, but in my experience I constantly encounter obstacles when I do this, so try to avoid this unless it is absolutely important to the problem.

eg. this question gives instructions on how to do this:

Give FullTrust to a UNC Resource for Visual Studio 2012 and .Net 4.0

I only ever tried this with VS2010, so (as indicated in the link) you may have better joy since 2012.

+45
Apr 25 '13 at 14:56
source share

For those who are facing this now, BEFORE YOU DO ANYTHING ... If you are sure that your classes / namespaces are correct and the restoration did not solve your problem:

Try restarting Visual Studio

What is it!

This seems to be a bug with Visual Studio 2012 (also seems to affect all other versions supporting XAML development)




Update. If restarting Visual Studio does not work, restart the entire computer.

Update. As mentioned in @Dunk comments, if restarting Visual Studio does not work, try deleting the .suo file

+106
Mar 14 '14 at 13:49
source share

I had the same problem, but my files are stored locally. My IValueConverter is in a different assembly than viewing it. Although VS2013 IntelliSense suggested the following, it did not work:

 xmlns:conv="clr-namespace:MySharedAssembly.Converters" 

After I explicitly added the assembly at the end, it worked:

 xmlns:conv="clr-namespace:MySharedAssembly.Converters;assembly=MySharedAssembly" 
+29
Jul 22 '14 at 18:35
source share

I stuck with this error for hours. Assemblies and namespaces were correct, classes and references were correct. Compile and work fine, only the designer had some problems with me. Only thing that worked

  • for design purposes swtich x64 to x86
  • to run and debug back to x64

I use 3d-party portable.library, which I only had in x64 version.

+10
Apr 09 '15 at 16:58
source share

DLL solution loaded

  • Unlock .dll file
    • Right click and select properties
    • Unlock it on the General tab (see image)
  • Make sure VS overrides XAML (possibly by restarting it).

enter image description here

+9
Dec 13 '15 at 13:09 on
source share

This still happens in VS 2015. I pulled SomeConverter into App.xaml:

 <Application.Resources> <!--Value Converters--> <local:SomeConverter x:Key="mySomeConverter"/> 

Strg-shift-b
Bring it back - and it worked.

+5
Nov 25 '15 at 12:58
source share

Create a symbolic link to the network share on the local drive.

Go to the command line and type mklink / DC: \ LOCALFOLDER \ YOURNETWORKPATH

Then open the projects from your local folder and all problems will disappear. Now all the files will still be in your network share. :)

+3
Jul 09 '14 at 10:22
source share

I started a new project and had this problem. None of the solutions listed here worked, including deleting the suo file, unloading / reloading the project, restarting VS, etc.

What worked for me, because it was a new project, I have not built it yet. I deleted the Window.DataContext element to the clipboard, built the project once (shift-ctrl-b), and then added the element again, and it functioned immediately.

+2
May 29 '15 at 8:33
source share

Before you try the broad solution, try the following:

I had the same problem, I closed the window / form that caused the error, and then ran the project,

The error seemed to disappear after the successful completion of the project and did not return.

Hope this helps anyone looking for a quick solution.

+2
Sep 06 '16 at 10:03
source share

I got the same error in Visual Studio 2015 and managed to get the designer to work by unchecking the "Disable project code button" checkbox.

Screenshot to the designer button

+2
Feb 23 '17 at 15:05
source share

It annoyed me for years 2008, 10, 12, 13.

Whenever this happens (yes, I’m working on a network resource - I can’t avoid it), I close VS, rename FOLDER and open the project again. 9 times out of 10, it works. For a while.

0
Jun 09 '14 at 15:17
source share

For someone else stuck.

What worked for me was to change the namespace alias from local to anything else.

 xmlns:local="clr-namespace:ExampleNameSpace.Folder" /> <Grid> <StackPanel> <local:ReferencedUserControl /> </StackPanel> </Grid> 

to

 xmlns:blah="clr-namespace:ExampleNameSpace.Folder" /> <Grid> <StackPanel> <blah:ReferencedUserControl /> </StackPanel> </Grid> 

Hope this helps!

0
Dec 07 '15 at 11:16
source share

There was the same problem. For me, this was when I realized that the class in question was marked as internal :

 internal class MyClass { } 

After changing it to public developer was able to compile XAML correctly.

0
Jan 29 '16 at 23:44
source share

What worked for me was to change MOVE to XCOPY in Post Build in project properties and then re-build project. The designer may need a dll in the project output folder. I am using vs 2015

0
Mar 29 '16 at 18:20
source share

After rebooting Visual Studio, I received an IntelliSense error that pointed me in the right direction.

Since the 'Microsoft.VisualStudio.DesignTools.Xaml.LanguageService.Semantics.Metadata.ReflectionTypeNode' runs in the same assembly, you must set the x: Name attribute and not the Microsoft.VisualStudio.DesignTools.Xaml.LanguageService.Semantics.Metadata.RefProper attribute.

So, I changed this:

 <local:MyView Name="test"/> 

For this:

 <local:MyView x:Name="test"/> 

And then it worked. So what gives us? 42 possible reasons? Unreal ...

0
Oct 14 '16 at 2:37
source share

I also have a project on a network share, and this error suddenly appeared. I tried all of the above suggestions, including copying the project to a local drive, cleaning, rebuilding and opening and closing VS. None of them solved the problem.

What worked for me simply deleted the namespace link in the viewmodels folder (xlmns: vm = "clr-namespace: Myproj.ViewModel").

I added a type to my xaml (DataTemplate DataType = "{x: Type vm: myviewmodel}"). Then Visual Studio found that the namespace was missing, and I clicked on the prompt to add the namespace.

0
Oct 20 '16 at 6:44
source share

Declaring this resource dictionary worked for me.

 <Window.Resources> <c:IsNullConverter x:Key="IsNullConverter" /> </Window.Resources> 

The problem is that the parser itself Converter={c:IsNullConverter}}" when it sees a markup extension, for example Converter={c:IsNullConverter}}" , but fine with: Converter={StaticResource IsNullConverter} . I think maybe where the problem is .

Windows 10, VS 2013

0
Nov 29 '16 at
source share

I had 3 errors in the project and focused on this error related to ObjectDataProvider. I found out that this error cannot be resolved if the project cannot build due to other errors. I had a few more event handlers whose code was deleted. I also needed to remove the code that tried to associate the handlers with the controls. Then the project was able to build and see that the class that I was trying to reference from ObjectDataProvider was available.

0
Jul 22 '17 at 18:54
source share

The name "XYZ" does not exist in the namespace "clr-namespace: ABC"

SOLVE!!

check if there is a function you want to call / the class is present in the namespace

The correct example is:

.XAML file

  <Window x:Class="objectbinding.MainWindow" <!--your xmlns:x ....... namespace1 is the project name--> xmlns:m="clr-namespace:namespace1" Title="MainWindow" Height="350" Width="525"> <Grid> <StackPanel Orientation="Vertical"> <StackPanel.Resources> <ObjectDataProvider ObjectType="{x:Type m:StringData}" x:Key="anyname" MethodName="GetStrings"/> </StackPanel.Resources> 

  ItemsSource="{Binding Source={StaticResource Runni}}" /> </StackPanel> </Grid> 

// StringData is the class name in xaml.cs, and GetString is a function

.XAML.CS file

  namespace namespace1 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } } // the class StringData is defined in namespace namespace 1 public class StringData { ObservableCollection<String> lst = new ObservableCollection<String>(); public StringData() { lst.Add("Abhishek"); lst.Add("Abhijit"); lst.Add("Kunal"); lst.Add("Sheo"); } public ObservableCollection<String> GetStrings() { return lst; } } } 

Invalid example:

.XAML file

  <Window x:Class="objectbinding.MainWindow" <!--your xmlns:x ....... namespace1 is the project name--> xmlns:m="clr-namespace:namespace1" Title="MainWindow" Height="350" Width="525"> <Grid> <StackPanel Orientation="Vertical"> <StackPanel.Resources> <ObjectDataProvider ObjectType="{x:Type m:StringData}" x:Key="anyname" MethodName="GetStrings"/> </StackPanel.Resources> 

  ItemsSource="{Binding Source={StaticResource Runni}}" /> </StackPanel> </Grid> 

.XAML.CS

 namespace namespace1 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } //The StringData is defined in the class mainWindow not in namespace namespace1 public class StringData { ObservableCollection<String> lst = new ObservableCollection<String>(); public StringData() { lst.Add("Abhishek"); lst.Add("Abhijit"); lst.Add("Kunal"); lst.Add("Sheo"); } public ObservableCollection<String> GetStrings() { return lst; } } } } 
0
Nov 20 '17 at 8:52
source share

In my case, this error was caused by the fact that the subscription of assemblies with the "delay" signal turned on was turned on. The solution was to run the sn -Vr * command from the developer console (as an administrator). This registers the assembly for skipping passes. Then restart Visual Studio.

0
Dec 01 '17 at 11:12
source share

This may be due to the release configuration. The designer should be used from the Debug configuration.

-2
Feb 20 '16 at 22:32
source share



All Articles