title: Type not found in cache
body: <p>I'm trying to put an universal app together and I'm using mvvm light but I'm getting the following error when compiling my app:</p>
  
  <pre><code>Error   1   Type not found in cache: MyApp.Model.LocationModel
  ...\MyApp.WindowsPhone\Views\LocationPage.xaml  10  5   MyApp.WindowsPhone
  </code></pre>
  
  <p>It does compile successfully but I can't figure out what's causing the problem. I've found a couple of article on stackoverflow:</p>
  
  <p><a href="https://stackoverflow.com/questions/17175893/simpleioc-type-not-found-in-cache-windows-ui-xaml-controls-frame">SimpleIoC - Type not found in cache: Windows.UI.Xaml.Controls.Frame</a></p>
  
  <p><a href="https://stackoverflow.com/questions/23591374/mvvm-light-type-not-found-in-cache">MVVM Light “Type Not Found in cache”</a></p>
  
  <p>But neither one apply to my problem. The first thing I've noticed is that the error is somehow displaying a Model where the problem resides rather than a ViewModel.</p>
  
  <pre><code>Error   1   Type not found in cache: MyApp.Model.LocationModel. 
  ...\MyApp\MyApp.WindowsPhone\Views\LocationPage.xaml    10  5   MyApp.WindowsPhone
  </code></pre>
  
  <p>The error in my xaml occurs on the line where I defined my DataContext:</p>
  
  <pre><code>&lt;Page
  ....
  DataContext="{Binding Source={StaticResource Locator}, Path=LocationViewModel}"&gt;
  </code></pre>
  
  <p>My LocationViewModel class is defined as follows:</p>
  
  <pre><code>public class LocationViewModel : ViewModelBase
  {
      private RelayCommand _saveCommand;
      private RelayCommand _cancelCommand;
  
      #region Properties
  
      public int Id
      {
          get
          {
              return this.Location.Id;
          }
      }
  
      public string Title
      {
          get
          {
              return this.Location.Title;
          }
      }
  
      public string Description
      {
          get
          {
              return this.Location.Description;
          }
      }
  
      public string CreatedDateFormatted
      {
          get
          {
              return this.Location.CreatedDate.ToString("d");
          }
      }
  
      public string LastUpdatedDateFormatted
      {
          get
          {
              return Location.LastUpdatedDate.ToString("d");
          }
      }
  
      public string ImagePath
      {
          get
          {
              return this.Location.ImagePath;
          }
      }
  
      public LocationModel Location
      {
          get;
          private set;
      }
  
      #endregion
  
      #region Constructors
  
      public LocationViewModel(LocationModel model)
      {
          this.Location = model;
          this.Location.PropertyChanged += (s, e) =&gt;
              {
                  if (e.PropertyName == LocationModel.DescriptionPropertyName)
                  {
                      RaisePropertyChanged(() =&gt; Description);
                  }
                  if (e.PropertyName == LocationModel.TitlePropertyName)
                  {
                      RaisePropertyChanged(() =&gt; Title);
                  }
                  if (e.PropertyName == LocationModel.ImagePathPropertyName)
                  {
                      RaisePropertyChanged(() =&gt; ImagePath);
                  }
                  if (e.PropertyName == LocationModel.CreatedDateStringPropertyName)
                  {
                      RaisePropertyChanged(() =&gt; CreatedDateFormatted);
                  }
                  if (e.PropertyName == LocationModel.LastUpdatedDateStringPropertyName)
                  {
                      RaisePropertyChanged(() =&gt; LastUpdatedDateFormatted);
                  }
              };
      }
  
      #endregion
  
      public RelayCommand SaveCommand
      {
          get
          {
              return this._saveCommand ?? (this._saveCommand = new RelayCommand(ExecuteSaveCommand));
          }
      }
  
      public RelayCommand CancelCommand
      {
          get
          {
              return this._cancelCommand ?? (this._cancelCommand = new RelayCommand(ExecuteCancelCommand));
          }
      }
  
  
      private void ExecuteSaveCommand()
      {
  
      }
  
      private void ExecuteCancelCommand()
      {
  
      }
  }
  </code></pre>
  
  <p>and my property for my LocationViewModel is defined as follows in my ViewModelLocator class:</p>
  
  <pre><code>    public LocationViewModel LocationViewModel
      {
          get
          {
              return ServiceLocator.Current.GetInstance&lt;LocationViewModel&gt;();
          }
      }
  </code></pre>
  
  <p>and is registered in the ViewModelLocator's constructor:</p>
  
  <pre><code>SimpleIoc.Default.Register&lt;LocationViewModel&gt;();
  </code></pre>
  
  <p>and when this code is called, it registers my LocationViewModel correctly.</p>
  
  <p>When click on my "add" button, it navigate to the page where the LocationViewModel is set as the DataContext and the error occurs at run-time. </p>
  
  <p>The code I'm calling from <code>LocationsViewModel</code> (not <code>LocationViewModel</code>) that's calling the navigation is:</p>
  
  <pre><code>    private void ExecuteAddCommand()
      {
          _navigationService.Navigate(typeof(LocationPage));
      }
  </code></pre>
  
  <p>When debugging the above, it creates the LocationPage, followed by calling the LocationViewModel from the ViewModelLocator and this is when the same error occurs but at run-time i.e.</p>
  
  <pre><code>return ServiceLocator.Current.GetInstance&lt;LocationViewModel&gt;();
  </code></pre>
  
  <p>When I move my mouse over the , it displays the following:</p>
  
  <pre><code>Message: "Type not found in cache: MyApp.Model.LocationModel."
  InnerException: at GalaSoft.MvvmLight.Ioc.SimpleIoc.DoGetService
  (Type serviceType, String key) at 
  GalaSoft.MvvmLight.Ioc.SimpleIoc.GetInstance[TService]()
  at Inventory.ViewModel.ViewModelLocator.get_LocationViewModel()
  </code></pre>
  
  <p>Actually, I've just realized that the error is generated much earlier but no error is thrown. It is actually generated when registering the LocationViewModel in the constructor of ViewModelLocator:</p>
  
  <pre><code>SimpleIoc.Default.Register&lt;LocationViewModel&gt;();
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks.</p>