CM1.1 Bootstrapper.GetInstance called with null arguments

Topics: Bootstrappers & IoC
Jul 2, 2011 at 11:26 PM


I have just upgraded my WP7 app from CM 1.0 to 1.1 and I am having troubles with Bootstrapper.GetInstance.

The first time Bootstrapper.GetInstance is called, both the service and key arguements are null. If I let this run into PhoneContainer.GetInstance, I get an InvalidOperationException with the message "Sequence contains more than one element".

Why would both the service and key arguments be null??


I am pretty certain CM is trying to resolve the ViewModel for the main page because the previous entry on the stack trace looks like this:

  Caliburn.Micro.dll!Caliburn.Micro.ViewModelLocator..cctor.AnonymousMethod__8(System.Type viewType = {Name = "MainPageView" FullName = "Clients.WinPhone.Silverlight.View.MainPageView"}) + 0x46 bytes

I renamed my MainPage, to MainPageView just as a test to see if there were problems with the ViewModelLocator logic for MainPage, but it has made no difference.

I have also made sure I registered my view model earlier in Bootstrapper.Configure like this (this are the only 3 lines in the Configure method):

        Settings.Container = new PhoneContainer(RootFrame);

All help much appreciated.






Jul 3, 2011 at 4:39 AM

Can you update to the latest and see if the problem is fixed? 

Jul 3, 2011 at 5:49 PM


I tried the lates CM code. Substituted the new DLLs straight in for the old and rebuilt my solution. Now Bootstrapper.GetInstance does not even get called to resolve the VM for MainPage.


Jul 3, 2011 at 6:10 PM

Hmmm. Can you email me a sample that reproduces the problem? Send it to robertheisenberg at hotmail dot com   I'll have a look at it this week and either get a fix in or make a recommendation to you. Thanks in advance!

Jul 3, 2011 at 7:31 PM
Edited Jul 3, 2011 at 8:08 PM


[Edited after more investigation]

Looking at the latest ViewModelLocator, it seems that the defualt transforms do not work with the namespaces I have chosen. For example, this is the namespace containing my views:


But it looks like the default rules want plural "Views" at the end.

I will add a rule and see if I can get it working.



Jul 3, 2011 at 8:16 PM

Ah. Yes. That is correct. The default patterns look for "Views" plural. But, you can easily add new rules for what you want. 

Jul 3, 2011 at 8:37 PM
Edited Jul 3, 2011 at 8:39 PM

Hi There,

Next problem is that my Views and ViewModels are in different assemblies, so line 115 in ViewModelLocator:

var viewModelType = (from assembly in AssemblySource.Instance
                                 from type in assembly.GetExportedTypes()
                                 where viewModelTypeList.Contains(type.FullName)
                                 select type).FirstOrDefault();

...does not resolve my ViewModel class because its containing assembly is not in the AssemblySource collection. Any suggestions on the preferred way to add my ViewModel assembly to the AssemblySource collection? Just add it during bootstrap?

[Edit] - OK, suggestion in source is to override SelectAssemblies method - will do that.