Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

[Bug] MainThread.BeginInvokeOnMainThread crashes on Windows if called too early #1020

Closed
tipa opened this issue Dec 13, 2019 · 2 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@tipa
Copy link
Contributor

tipa commented Dec 13, 2019

Description

If MainThread.BeginInvokeOnMainThread is called to early, it crashes with

System.InvalidOperationException: 'A method was called at an unexpected time.
Could not create a new view because the main window has not yet been created'

Steps to Reproduce

Execute MainThread.BeginInvokeOnMainThread in app constructor

Expected Behavior

No crash, exception is caught and code is executed on current thread

Actual Behavior

It crashes here:

if (CoreApplication.MainView.CoreWindow == null)

Basic Information

  • Version with issue: Xamarin.Essentials 1.3.1

Reproduction Link

App3.zip

@tipa tipa added the bug Something isn't working label Dec 13, 2019
@jamesmontemagno
Copy link
Collaborator

Hmmm, i'll give it a try. this is master: https://github.com/xamarin/Essentials/blob/master/Xamarin.Essentials/MainThread/MainThread.uwp.cs i wonder what isn't null.

@jamesmontemagno
Copy link
Collaborator

I see, it basically throws an exception when we check :(

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants