NullReferenceException when used INavigation in WP7?

Topics: Getting Started
Jun 15, 2011 at 1:58 PM
Edited Jun 15, 2011 at 1:59 PM

Hello all,

i am trying to use the CM in my WP7 project, but i have a problem when using INavigationService to navigate to a new wp page.

I add a new Page "Page1.xaml" to the Caliburn.Micro.HelloWP7 project, create a ViewModel "Page1ViewModel" for it.

And i also regist in HelloWP7Bootstrapper




here is my viewmodel

namespace Caliburn.Micro.HelloWP7
    public class Page1ViewModel
         readonly INavigationService navigationService;

         public Page1ViewModel(INavigationService navigationService)
            this.navigationService = navigationService;


after, i made GotoPageTwo navigate to the new page


 public void GotoPageTwo() {
                .WithParam(x => x.NumberOfTabs, 5)
            //navigationService.Navigate(new System.Uri("/Page1.xaml", System.UriKind.RelativeOrAbsolute));

i got a nullreferenceexption when click GotoPageTwo. 
When i changed to :
navigationService.Navigate(new System.Uri("/Page1.xaml", System.UriKind.RelativeOrAbsolute));

it came up with a invalidOperationException:Sequence contains more than one element.
I really dont know how to use strongly typed navigation, can anybody give me some sample or tell me what's the problem of my code?

thanks in advance!
Jun 15, 2011 at 3:19 PM
Edited Jun 15, 2011 at 3:20 PM

in your bootstrapper do you have a line:


in your config override?

I am assuming you are version 1.1

Jun 15, 2011 at 3:45 PM
Edited Jun 15, 2011 at 3:46 PM


protected override void Configure() {
            container = new PhoneContainer(RootFrame);

            container.PerRequest<TabViewModel, TabViewModel>();

correct,i am using 1.1 and i do have RegisterPhoneServices, here is my Configure override
Jun 15, 2011 at 7:09 PM

I need you to email me a sample. We may have some bugs in our new stuff. Please create a simple soltution that reproduces the problem and email it to robertheisenberg at hotmail dot com

Jun 16, 2011 at 3:33 AM

Hello Reober,i have sent you the sample, please check it, thanks you very much

Jun 18, 2011 at 5:53 PM


I ran into the same issue. I discovered that my first mistake was following the mainpage.xaml/mainpageviewmodel.cs naming convention instead of newview.xaml/newviewmodel.cs. In addition I forgot to update the newview.xaml code behind class which was still public class newpage. in short make sure the code behind class name matches the .xaml file name...

Jun 20, 2011 at 4:10 AM
Edited Jun 20, 2011 at 4:11 AM

thank you very much, it fix my problem