title: Win10 UWP, Prism/Unity and Unit Tests plus Class Libraries, silent failure
body: <p>Basic layout is currently a simple app. Nothing fancy, I've got Views in the <code>App.Views</code> namespace and my ViewModels in the <code>App.ViewModels</code> namespace. The ViewModels are autowired to the Views through the XAML directive:</p>
  
  <pre><code>xmlns:prismMvvm="using:Prism.Windows.Mvvm"
  prismMvvm:ViewModelLocator.AutoWireViewModel="True"
  </code></pre>
  
  <p>So, basically, this works. Then I wanted to leverage Unity's IoC / DependencyInjection for some unit tests.</p>
  
  <p>The usual way would be to simply add a Windows 10 Unit Test App to the existing app and reference the latter in the Unit Test App.</p>
  
  <p>This will crash upon executing the unit tests because it seems that you may not derive the <code>App</code> class from anything other but <code>Application</code>.
  I.e. this works:</p>
  
  <pre><code>public sealed partial class App : Application
  </code></pre>
  
  <p>This does not:</p>
  
  <pre><code>public sealed partial class App : PrismUnityApplication
  </code></pre>
  
  <p>It's probably also not Prism's fault and something Microsoft has to fix on their end.</p>
  
  <p>Now, the proposed workaround is to simply put whatever you want to unit test into a class library and reference this library from the unit test app. This works for unit testing. It also works for the Models.</p>
  
  <p>My naive approach does not work, however, for the ViewModels. The ViewModel classes are still found under the <code>App.ViewModels</code> namespace, as before, just that they're now in a Class Library. I can access them programmatically in the main app just fine. But upon running the program, the AutoWiring silently fails without an error.</p>
  
  <p>Even when I do something like this, it still does not work:</p>
  
  <pre><code>ViewModelLocationProvider.Register(typeof(MainPage).ToString(), () =&gt; new ViewModels.MainPageViewModel());
  </code></pre>
  
  <p>I'm not that experienced with the technologies involved yet so without an actual error I'm a bit at a loss.</p>
  
  <p>edit: Just to add to the mystery - this code does work, regardless of whether the ViewModel resides in the main app or the class library:</p>
  
  <pre><code>var x = Container.Resolve(typeof(ExamplePageViewModel)) as ExamplePageViewModel;
  </code></pre>