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.04k stars 1.73k forks source link

`WinUI` unknown exception when running as `Project` instead of `MsixPackage` #21794

Open AndreasReitberger opened 5 months ago

AndreasReitberger commented 5 months ago

Description

I'm facing a problem while trying to release my app as Project on Windows. When I start the application set as Project in the LaunchSettings

{
  "profiles": {
    "Windows Machine": {
      //"commandName": "MsixPackage",
      "commandName": "Project",
      "nativeDebugging": false
    }
  }
}
<!-- https://stackoverflow.com/a/75589936/10083577 -->
<WindowsPackageType Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">None</WindowsPackageType>
<WindowsAppSDKSelfContained Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">true</WindowsAppSDKSelfContained>
<WindowsAppSdkDeploymentManagerInitialize Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">false</WindowsAppSdkDeploymentManagerInitialize>
<!-- set false to build an exe file instead -->
<GenerateAppxPackageOnBuild>false</GenerateAppxPackageOnBuild>

I get an Microsoft.UI.Xaml.UnhandledException exception.

Value does not fall within the expected range.

Stacktrace:

bei WinRT.ExceptionHelpers.gThrow|39_0(Int32 hr) bei WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr) bei ABI.Microsoft.Graphics.Canvas.ICanvasDrawingSessionMethods.DrawText(IObjectReference _obj, String text, Rect rectangle, Color color, CanvasTextFormat format) bei Microsoft.Graphics.Canvas.CanvasDrawingSession.DrawText(String text, Rect rectangle, Color color, CanvasTextFormat format) bei Syncfusion.Maui.Graphics.Internals.CanvasExtensions.DrawText(ICanvas canvas, String value, Rect rect, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, ITextElement textElement) bei Syncfusion.Maui.Core.SfBusyIndicator.DrawTitle(ICanvas canvas) bei Syncfusion.Maui.Core.SfBusyIndicator.OnDraw(ICanvas canvas, RectF dirtyRect) bei Syncfusion.Maui.Core.SfView.Microsoft.Maui.Graphics.IDrawable.Draw(ICanvas canvas, RectF dirtyRect) bei Syncfusion.Maui.Core.Platform.NativeGraphicsView.OnDraw(CanvasControl sender, CanvasDrawEventArgs args) bei WinRT._EventSource_globalWindows_Foundation_TypedEventHandler_global__Microsoft_Graphics_Canvas_UI_Xaml_CanvasControlglobalMicrosoft_Graphics_Canvas_UI_XamlCanvasDrawEventArgs.EventState.b__1_0(CanvasControl sender, CanvasDrawEventArgs args) bei ABI.Windows.Foundation.TypedEventHandler`2.Do_Abi_Invoke[TSenderAbi,TResultAbi](Void* thisPtr, TSenderAbi sender, TResultAbi args)

image

When I switch back to MsixPackage, the app works. Same applies for Android. Only WinUI as unpackaged built gives me this exception.

{
  "profiles": {
    "Windows Machine": {
      "commandName": "MsixPackage",
      //"commandName": "Project",
      "nativeDebugging": false
    }
  }
}
        <GenerateAppxPackageOnBuild>true</GenerateAppxPackageOnBuild>
        <AppxBundle>Always</AppxBundle>
        <AppxBundlePlatforms>x86|x64|arm</AppxBundlePlatforms>

image

I'm actually kinda lost how to debug the root-cause with this exception. The only which popsup on the working configuration is this Binding issue, which I cannot identify in my project source code.

Schweregrad Anzahl Datenkontext Bindungspfad Ziel Zieltyp Beschreibung Datei Zeile Projekt Fehler 1 Microsoft.UI.Xaml.Controls.SplitView TemplateSettings.CompactPaneGridLength Microsoft.UI.Xaml.Media.Animation.SplineDoubleKeyFrame.Value Double Converter failed to convert value of type 'Windows.Foundation.IReference`1' to type 'Double'

Maybe this is the reason why the Project build fails...

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.20 SR4

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

Publish as MsixPackage

Relevant log output

No response

AndreasReitberger commented 5 months ago

I nailed it down to setting the FontFamily for the SfBusyControl. If I remove the setter, it works. Seems to be an issue to find the font again, if released unpackaged.

Repro: https://github.com/AndreasReitberger/SfBusyIndicatorMauiIssue Reported also to syncfusion: https://support.syncfusion.com/support/tickets/579453

Edit: Seems to be relevant to each syncfusion control if setting the FontFamily and publish unpackaged

ninachen03 commented 5 months ago

Verified this issue with Visual Studio 17.10.0 Preview 3 (8.0.20 & 8.0.14).I can not repro this issue on windows machine.

AndreasReitberger commented 5 months ago

Verified this issue with Visual Studio 17.10.0 Preview 3 (8.0.20 & 8.0.14).I can not repro this issue on windows machine.

Are you able to publish the example as executable without a crash? It does not work on my end.

I'm on Win11 if that matters.

AndreasReitberger commented 5 months ago

Syncfusion has verified this issue and found the root cause at CanvasTextFormat

https://github.com/microsoft/Win2D/issues/941