WinRT 1.4 to 1.41 breaking change?

Topics: Bootstrappers & IoC, Bugs, Getting Started
Feb 12, 2013 at 7:42 PM
I get the following exception while creating a brand new WinRT project, I have confirmed that the same project works fine when targeting v1.4, this only happens since targeting 1.4.1.
System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
       at Caliburn.Micro.ViewLocator.<.cctor>b__e(Object model, DependencyObject displayLocation, Object context) in c:\Projects\caliburnmicro\src\Caliburn.Micro.Silverlight\ViewLocator.cs:line 440
       at Caliburn.Micro.CaliburnApplication.DisplayRootViewFor(Type viewModelType) in c:\Projects\caliburnmicro\src\Caliburn.Micro.WinRT\CaliburnApplication.cs:line 250
       at Caliburn.Micro.CaliburnApplication.DisplayRootViewFor[T]() in c:\Projects\caliburnmicro\src\Caliburn.Micro.WinRT\CaliburnApplication.cs:line 268
       at App6.App.OnLaunched(LaunchActivatedEventArgs args)
The project really is as simple as it gets, a new Blank windows store app with a ShellView.xaml and ShellViewModel.cs under the Shell namespace. Followed the documentation to modify App.xaml/cs and in OnLaunced a call to base.DisplayRootViewFor<Shell.ShellViewModel>();.

With some quick debugging it appears that in CaliburnApplication.cs line 249 IoC.GetInstance() is not returning an instance of the ViewModel and is instead returning null. Adding this.container.RegisterInstance(typeof(Shell.ShellViewModel), null, new Shell.ShellViewModel()); to the Configure override resolves the issue.

Is this expected behaviour or maybe an unforeseen consequence of this commit.
Many thanks, great work!
Feb 12, 2013 at 9:18 PM
The behaviour changed between 1.4 and 1.4.1 because the behaviour for WinRT in 1.4 was by mistake (see issue 280).

The behaviour of the container for Windows Phone was always like that only WinRT container was different. This changes fixes the mistake by aligning the WinRT container behavour to the Windows Phone container behaviour.

The documentation was also updated to show that you need to register your view models at the container (as you did for Windows Phone).
Feb 13, 2013 at 9:59 AM
Ok cool, lol I see that comment in the code as bight as day now.