The name ViewModel does not exist in the namespace “clr-namespace:Project.ViewModels”

前端 未结 18 1737
旧时难觅i
旧时难觅i 2020-12-04 23:55

Now that\'s a real strange error. I am working on a WPF application and following MVVM. In my MainWindow I am setting views and view models and I get this strange error. Alt

相关标签:
18条回答
  • 2020-12-05 00:37

    I ran into this error, and the problem was that I had a class within the project with the same name of the assembly I was trying to reference. I changed the class name and it worked.

    0 讨论(0)
  • 2020-12-05 00:37

    The solution is easy, just comment your DataType code and compile it first, uncomment the code back, then the problem is solved.

    XAML file just cannot refererence to namespaces that haven't been built.

    0 讨论(0)
  • 2020-12-05 00:38

    This error occurs because a xaml file references to unbuilt namespace.

    My Solution [ in 3 steps ]:

    1- Comment a problematic file[s] and replace with empty version. for example for yours:

    <!-- <Window ...> </Window> -->  <!--you orginal xaml code!, uncomment later-->
    
    <Window                          <!-- temp xaml code, remove later -->
        x:Class="MyProject.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    </Window>
    

    2- Clean and Rebuild the Project/Solution.

    3-Uncomment original xaml code and remove temp xaml code.

    it's done.

    0 讨论(0)
  • 2020-12-05 00:39

    None of the other answers solved the problem for me, but I eventually came up with an answer that did. In my case, this error only caused the designer to complain about invalid markup (i.e. everything worked fine at runtime).

    I had used ReSharper8 to rename one of my classes being referenced in the XAML. This caused another completely different class reference in that same XAML to have this error. This was confusing because the class causing the problem was NOT the same as the referenced class displaying the error.

    One of the other answers indicated that the error in question could be caused by renaming a project, and the only way to fix it was to remove and re-add that project. Similarly, I deleted and re-created the class file that I had renamed and the designer begin working again.

    0 讨论(0)
  • 2020-12-05 00:42

    Close and reopen Visual Studio.

    I tried some of the answers here (I'm using VS2012 with Resharper), and I was doing everything ok, but still had the error. I was even able to navigate to my bound fields using Resharper's 'cntl'+click, but was still getting XAML compile errors and designer wouldn't show the design view. Closing visual studio and reopening fixed it for me.

    0 讨论(0)
  • 2020-12-05 00:45

    I have been through this with Microsoft. The answer, in summary, is to add your build output folder to your PATH.

    Apparently, the designer in Visual Studio loads DLLs and their dependencies. When it can't find a dependency, it fails silently and you get these types of errors.

    Adding the build output folder to my PATH is not really an option in my case, because I build several different configurations and they all go to separate folders. The last thing I need to encounter some weird problem caused by a DLL being picked up from a location I hadn't anticipated.

    Edit: Sorry. In my haste, I should have pointed out that the folder(s) to add to the PATH are the folder(s) containing the dependent DLLs. In my case, this is the build output folder, but that may not be true in all cases.

    0 讨论(0)
提交回复
热议问题