2

This is my App.xaml.cs

[Bindable]
sealed partial class App : Template10.Common.BootStrapper
{
    public App()
    {
        InitializeComponent();
        SplashFactory = (e) => new Views.Splash(e);

        var _settings = SettingsService.Instance;
        RequestedTheme = _settings.AppTheme;
        CacheMaxDuration = _settings.CacheMaxDuration;
        ShowShellBackButton = _settings.UseShellBackButton;
    }

    public override async Task OnInitializeAsync(IActivatedEventArgs args)
    {
        if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
        {
            var statusBar = StatusBar.GetForCurrentView();
            await statusBar.HideAsync();
        }

        await Task.CompletedTask;
    }

    public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
    {
        NavigationService.Navigate(typeof(Views.MainPage)); // Exception here
        await Task.CompletedTask;
    }
}

Every time i launch the app i get this exception:

System.NullReferenceException verificata HResult=-2147467261 Message=Object reference not set to an instance of an object.

NavigationService is always null.

How can I solve this?

frenk91
  • 919
  • 1
  • 15
  • 30
  • I tested with your code, it works well. The code you've posted is right. I think the problem may not be here. Could you share a [mcve] that can reproduce your issue? Or you can test your code with a Minimal Template 10 project, it should be able to work. – Jay Zuo Sep 14 '16 at 05:34
  • If i create a new project this code works fine – frenk91 Sep 14 '16 at 07:25

3 Answers3

2

I had the same issue when I updated the Target min version of the project to Fall Creators Update (see project properties).

After reading this thread I fixed the issue by updating the Newtonsoft.Json Nuget dependency from version 11.x.x to 10.0.3.

So just to be clear I downgraded the version of the Newtonsoft.Json Nuget dependency.

Floris Devreese
  • 3,127
  • 2
  • 21
  • 31
1

For anyone coming back to this, I run across issue and realized that if I kept the minimum version of the project 10586 the problem goes away.

0

I have had similar issue, but inside of ViewModel not in App.xaml.cs.

So NavigationService was null when I defined and initialized my ViewModel as property in code behind of view.

Solution is to define ViewModel in xaml (<Page.DataContext>) then everything works like a charm.

Yura
  • 75
  • 1
  • 8
  • I know this is a little old, but I am having this issue as well. Can you please explain exactly what you did to fix this? I would really appreciate it! – digthewells Oct 15 '18 at 13:09