dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.05k stars 1.73k forks source link

WinUI3 Maui Essentials Share Dialog results in a crash on Windows 10 21H2 (Build19044.3086) #17247

Open SprengerS opened 1 year ago

SprengerS commented 1 year ago

Description

If you want to open a Share Dialog on an WinUI3 App you get the following Nullreference Exception

The active Window can not be detected. Ensure that you have called Init in your Application class.

at Microsoft.Maui.ApplicationModel.WindowStateManagerExtensions.GetActiveWindowHandle(IWindowStateManager manager, Boolean throwOnNull) in Microsoft.Maui.ApplicationModel\WindowStateManagerExtensions.cs:line 28

grafik

This Exception is not thrown for an UWP Build with Xamarin Essentials.

I have initialized the WinUI3 App for Maui in App.xaml like this way in the documentation

MauiAppBuilder builder = MauiApp.CreateBuilder();
builder.UseMauiEmbedding<Microsoft.Maui.Controls.Application>();
MauiApp mauiApp = builder.Build();

Steps to Reproduce

  1. Create a WinUI3 App
  2. Use Maui Essentials for a Share Dialog
  3. Show the Share Dialog

Link to public reproduction project repository

No response

Version with bug

7.0.92

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 21H2 (Build19044.3086), Windows App SDK, 1.3.230724000

Did you find any workaround?

No response

Relevant log output

No response

jfversluis commented 1 year ago

This doesn't look like a typical .NET MAUI app since you're using MauiEmbedding? Why is that?

If you just create a File > New .NET MAUI project, does this same behavior occur as well? It would be really helpful if you add a reproduction repository so we can see the full project.

ghost commented 1 year ago

Hi @SprengerS. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

SprengerS commented 1 year ago

No I have migrated our App form Xamarin.Native for iOS, Android and UWP to .NET7 for iOS, Android and WinUI3. We cannot use Xamarin Essentials anymore, so we migrated to Maui.Essentials. For Native Embedding we added Code you described in https://learn.microsoft.com/de-de/dotnet/maui/platform-integration/native-embedding

I cannot give you the whole repository because it includes our business logic

jfversluis commented 1 year ago

I understand you can't just give us your project, nor do we want that.

You can find the how and why on our documentation about it here: https://github.com/dotnet/maui/blob/main/.github/repro.md#how-to-provide-a-reproduction-project

Providing a minimal reproducible sample can greatly speed up the process.

SprengerS commented 1 year ago

This is my minimal Project. I don't understand why i cannot initialize Maui Embedding like in my original App. This is something strange. But this Project throws the same exception like my original source code.

ShareDialogTest.zip

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.8.0 Preview 2.0. Repro on Windows 11(8.0.0-rc.1) with below Project: Maui-Share-Dialog.zip

image