title: Getting System.Windows.Markup.XamlParseException while trying to run WP8 app
body: <p>I am writing Windows Phone 8 application and using MVVM light. I have written ViewModel and Model class of WP8 app into seperate PCL project.</p>
  
  <p>While using Expression Blend it properly populate design time data. But when I try to run app in emulator it get following error. Could you please help me in figuring out the fix to this error.</p>
  
  <pre><code>A first chance exception of type 'System.Windows.Markup.XamlParseException' 
  occurred in System.Windows.ni.dll
  </code></pre>
  
  <p>Here is details of Exception.</p>
  
  <pre><code>System.Windows.Markup.XamlParseException occurred
    HResult=-2146233087
    Message=Cannot create instance of type 'MyPkg.Commons.ViewModel.ViewModelLocator' [Line: 12 Position: 61]
    Source=System.Windows
    LineNumber=12
    LinePosition=61
    StackTrace:
         at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
         at MyPkg.WindowsPhone8.App.InitializeComponent()
         at MyPkg.WindowsPhone8.App..ctor()
    InnerException: System.TypeInitializationException
         HResult=-2146233036
         Message=The type initializer for 'MyPkg.Commons.ViewModel.ViewModelLocator' threw an exception.
         Source=mscorlib
         TypeName=MyPkg.Commons.ViewModel.ViewModelLocator
         StackTrace:
              at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
              at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
              at MS.Internal.TypeProxy.&lt;&gt;c__DisplayClass32.&lt;GetCreateObjectDelegate&gt;b__2c()
              at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId)
              at MS.Internal.XamlManagedRuntimeRPInvokes.CreateInstance(XamlTypeToken inXamlType, XamlQualifiedObject&amp; newObject)
         InnerException: System.IO.FileLoadException
              HResult=-2146234304
              Message=Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
              Source=MyPkg.Commons
              StackTrace:
                   at MyPkg.Commons.ViewModel.ViewModelLocator..cctor()
              InnerException: 
  </code></pre>
  
  <p>Below is App.xaml</p>
  
  <pre><code>&lt;Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
               xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
               xmlns:vm="clr-namespace:MyPkg.Commons.ViewModel;assembly=MyPkg.Commons"
               mc:Ignorable="d" x:Class="MyPkg.WindowsPhone8.App"&gt;
    &lt;!--Application Resources--&gt;
    &lt;Application.Resources&gt;
      &lt;local:LocalizedStrings xmlns:local="clr-namespace:MyPkg.WindowsPhone8" x:Key="LocalizedStrings" /&gt;
          &lt;vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True"  /&gt;
    &lt;/Application.Resources&gt;
    &lt;Application.ApplicationLifetimeObjects&gt;
      &lt;!--Required object that handles lifetime events for the application--&gt;
      &lt;shell:PhoneApplicationService Launching="Application_Launching" Closing="Application_Closing" Activated="Application_Activated" Deactivated="Application_Deactivated" /&gt;
    &lt;/Application.ApplicationLifetimeObjects&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p>Below code constructor of ViewModelLocator</p>
  
  <pre class="lang-cs prettyprint-override"><code>   static ViewModelLocator()
      {
          ServiceLocator.SetLocatorProvider(() =&gt; SimpleIoc.Default);
  
          if (ViewModelBase.IsInDesignModeStatic)
          {
              // Create design time view services and models
              SimpleIoc.Default.Register&lt;IAlaramService, MyPkg.Commons.Design.AlaramService&gt;();
          }
          else
          {
              // Create run time view services and models
              SimpleIoc.Default.Register&lt;IAlaramService, MyPkg.Commons.Design.AlaramService&gt;();
          }
  
          SimpleIoc.Default.Register&lt;MainViewModel&gt;();
      }
  </code></pre>