Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Adding a UWP project to the mobile solution #8560


User avatar
0
piapps created

Hi guys,

So I am in the process of trying to create a UWP project in the mobile solution, everything compiles when it runs I am getting a null exception at line 56 of LoginViewModel in Mobile.Shared\ViewModels\LoginViewModel

It appears everything under applicationContext is null (applicationContext.Configuration etc), i have a feeling that maybe the DI is not working correctly or something like that but I am having trouble trying to see exactly what is wrong

My UWP is just a blank UWP that I have added a Locale.cs to (to match the other mobile projects), then added references to Application.Client Application.Shared Core.Shared Mobile.Shared

It wouldnt compile without all 4 even though only 2 are needed, also has Flurl and Flurl.Http, Xamarin.Forms (same versions as the other projects) The MainPage.xaml.cs has this.LoadApplication(new App()); added to the ctor and inheritance to Page removed from the class while WindowsPage was added to the xaml markup App.xaml.cs has had the following added to the OnLaunched event

ApplicationBootstrapper.InitializeIfNeeds<NAMESPACEXamarinUWPModule>();

AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;

base.OnLaunched(e); //Xamarin.Forms.Forms.Init(e); global::Xamarin.Forms.Forms.Init(e);

ImageCircleRenderer.Init(); CachedImageRenderer.Init();

ConfigureFlurlHttp();

and the App.xaml.cs inherits from Windows.UI.Xaml.Application

So I think either the App.xaml is inherting maybe from the wrong thing or OnLaunched might be wrong event perhaps or I need more references in the project to fix up the applicationContext null thing but im not really sure can anyone help?

Regards, Pete


4 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    hi,

    did you see https://support.aspnetzero.com/QA/Questions/6273

  • User Avatar
    0
    piapps created

    Hi alper,

    Yes I did see that post and used it to piece together some of the requirements to get the UWP project started. My problem is related to appContext being null when trying to load the LoginViewModel. I cant see how it relates to AsyncCommand at all?

    I believe that appContext is being resolved before its properties are assigned

    Regards, Pete

  • User Avatar
    0
    alper created
    Support Team

    hi,

    AppContext is located here. It uses a lazy resolve, means it's being resolved for the initial access.

    In AppContext there's a resolve method.

    Locate a breakpoint here to see if it's being resolved. I guess it doesn't resolve none of your dependencies. (Maybe UWP doesn't work well with Castle Windsor.)

    One other crutial point is every new project must have an AbpModule to resolve dependencies. See Module System for AspNet Boilerplate.

  • User Avatar
    0
    piapps created

    Hi alper,

    Yep already created the module and I figured out the issue, it was that the UserConfigurationManager needs to actually be called to intialise the app context before any view model or anything using app context is called. It is done in droid in the SplashActivity but for iOS in the main shared project App.xaml.cs. I added a clause for UWP in the App.xaml.cs of the shared project too and it resolves the properties as expected.

    There are other issues in the UWP project in relation to look and design but at least it runs so now I can focus on that.

    Appreciate the help too thanks