Xamarin.Forms previewer errors related to Ninject (Visual Studio 2017)

DevologyDevology GBMember ✭✭

Hi,

I have a relatively new project setup in VS2017 with Android, iOS and Windows UWP. When I try to preview I get an error related to my use of Ninject :disappointed:

Unfortunately I can't copy and paste, or resize the window that displays the stack trace, but hopefully someone can understand why this is happening?

It seems to be when it goes off to initialise the StandardKernel for Ninject, it says getbasedirectories object reference not set to an instance, it hasn't even reached the part where it tries to add my bindings, so I don't think it's related to anything I've done.

using MyTeamSafe.Services;
using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyTeamSafe
{
    public class NinjectService
    {

        public StandardKernel kernel
        {
            get;
            set;
        }

        private static readonly Lazy<NinjectService> lazy =
            new Lazy<NinjectService>(() => new NinjectService());

        public static NinjectService Instance { get { return lazy.Value; } }

        private NinjectService()
        {
            kernel = new StandardKernel(); // <<<<--- BLOWS UP HERE
            init();  // DOESNT GET TO MY STUFF BELOW
        }


        protected void init()
        {
            kernel.Bind<Logger>().ToSelf().InSingletonScope();
            kernel.Bind<RestService>().ToSelf().InSingletonScope();
            kernel.Bind<AuthenticationService>().ToSelf().InSingletonScope();
            kernel.Bind<StorageService>().ToSelf().InSingletonScope();
            kernel.Bind<App>().ToSelf().InSingletonScope();
            kernel.Get<Logger>().Log(this, "Completed");
        }

    }
}

The app works fine on the Android and iOS device. I appreciate some insights to enable me to use the previewer. I also plan to try the Live preview app with the alpha of Visual Studio, but using the lightweight previewer would be preferable at this time.

Many thanks
Rob.

Sign In or Register to comment.