KrzJoa
KrzJoa

Reputation: 71

The name "ViewModelLocator" does not exist in the namespace

I'm just writing some training Windows project using MVVM Light Toolkit. Where the MVVM Light reference was added to the project, the following resource was automatically added to the App.xml

  <Application x:Class="TestApp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:TestApp" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
  <Application.Resources>
    <ResourceDictionary>
      <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="using:TestApp.ViewModel" />
    </ResourceDictionary>
  </Application.Resources>
</Application>

Unfortunately, it doesn't work, i.e. the project cannot be build/compiled because of these errors:

Blockquote Severity Code Description Project File Line Suppression State Error Unknown type 'ViewModelLocator' in XML namespace 'using:TestApp.ViewModel' TestApp.Windows C:\Users\Krzysztof\documents\visual studio 2015\Projects\TestApp\TestApp\TestApp.Shared\App.xaml 4
Error The name "ViewModelLocator" does not exist in the namespace "using:TestApp.ViewModel". TestApp.Windows C:\Users\Krzysztof\documents\visual studio 2015\Projects\TestApp\TestApp\TestApp.Shared\App.xaml 4

Briefly, I can't add the ViewModelLocator to the App.xml resources.

I found several common solutions for this problem (e.g.: changing solution platform, cleaning, rebuilding, restarting Visual Studio etc.) , but they change nothing. Creating a new project doesn't help as well.

Is there any other way to make it work? I use Visual Studio Community 2015.

Upvotes: 1

Views: 2579

Answers (3)

Jeremy Little
Jeremy Little

Reputation: 364

Comment out the auto-added sections of your viewmodel.xaml and the app.xaml and rebuild (with presumably no errors). Then uncomment the app.xaml - it should appear fine, if not sorry, can't help you any more. If so, then add in your datacontext to your view.

I ran into this too but to me, it appeared more to be an issue of the app.xaml attempting to access a fully built assembly reference and the visual studio interpreter not being sufficient.

Upvotes: 1

Ben
Ben

Reputation: 501

In the project properties just select Any CPU to the platform target

Upvotes: 0

Deepak Dk
Deepak Dk

Reputation: 33

I also suffer with the same problem and after searching a lot in google ,finally it resolve . so first check your project built platform, by right click on your project then go to property and check the built platform (x64,x84) options are there. after you confirm then goto toolbar(project window screen) and click built, inside built find configuration manager and check the active solution platform options .Both configuration manager and your project built be same. if not then change every platform and check.I hope this will help you..

Upvotes: 2

Related Questions