Skip to content

Attempt to fix crash in MauiApplication.OnCreate() #22911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

PavloLukianets
Copy link
Contributor

Description of Change

Just for test purposes to see app behavior when adding this null check

Issues Fixed

Fixes #21973
(not sure if fixes)

@PavloLukianets PavloLukianets requested a review from a team as a code owner June 7, 2024 14:58
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jun 7, 2024
@PavloLukianets PavloLukianets changed the title add null check for test Attempt to fix crash in MauiApplication.OnCreate() Jun 7, 2024
@jfversluis
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@mattleibow
Copy link
Member

An app without services is a really broken app and noting will actually launch.

In fact, this error is really weird because:

var mauiApp = CreateMauiApp();
var rootContext = new MauiContext(mauiApp.Services, this);
var applicationContext = rootContext.MakeApplicationScope(this);

_services = applicationContext.Services;

The CreateMauiApp should always create a new services instance. This is where you are registering your app services.

However, if you look at the exception, you can see the real issue is coming from Compatibility:

var services = IPlatformApplication.Current.Services;
var mauiContext = new MauiContext(services, app);

Are you using anything from compatibility?

But, this still gets more weird. The constructor of MauiApplication is setting IPlatformApplication.Current = this and by the time this event is fired, the services are set so IPlatformApplication.Current.Services should not be null.

I am going to add some more comments to the linked issue for duscussion and see if we can figure out some repro and/or info on the scenarios that cause this to happen - it seems impossible.

@PavloLukianets
Copy link
Contributor Author

PavloLukianets commented Jun 7, 2024

Are you using anything from compatibility?

Yeah, we have .UseMauiCompatibility(). So, in theory if we migrate all the left over renderers we have and remove this line everything should be ok?

@PureWeen PureWeen added the area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events label Jun 8, 2024
@mattleibow
Copy link
Member

Yeah, you might be able to use renders still, if you manually register them.

@PureWeen do we have docs on how to migrate the old renderers to the rendlers or handerers (the renderer-looking handlers).

@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events community ✨ Community Contribution
Projects
None yet
4 participants