Skip to content
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

Unpackaged Fabulous Maui app crashes at startup #3

Open
0x0309 opened this issue Jul 8, 2023 · 1 comment
Open

Unpackaged Fabulous Maui app crashes at startup #3

0x0309 opened this issue Jul 8, 2023 · 1 comment

Comments

@0x0309
Copy link

0x0309 commented Jul 8, 2023

Steps to reproduce

  1. dotnet new fabulous-mauicontrols -n MauiExample.App
  2. dotnet build succeeds and the app can be run
  3. Add the following properties to the fsproj
    • <WindowsPackageType Condition="$(TargetPlatformIdentifier) == 'windows'">None</WindowsPackageType>
    • <WindowsAppSdkUndockedRegFreeWinRTInitialize Condition="$(TargetPlatformIdentifier) == 'windows'">false</WindowsAppSdkUndockedRegFreeWinRTInitialize>
  4. Update Main.fs (manually initialize because WindowsAppSdkUndockedRegFreeWinRTInitialize doesn't yet work out-of-the-box for F#, Can't build fsproj with WindowsPackageType=None microsoft/WindowsAppSDK#3663)
open System.Runtime.InteropServices
module private NativeMethods =
    [<DllImport("Microsoft.WindowsAppRuntime.dll", CharSet = CharSet.Unicode, ExactSpelling = true)>]
    extern int WindowsAppRuntime_EnsureIsLoaded()

[<AbstractClass; Sealed>]
type Initializer =

    static member AccessWindowsAppSDK () =
        NativeMethods.WindowsAppRuntime_EnsureIsLoaded ()
        |> ignore // safe to ignore return value


module Program =
    [<EntryPoint; STAThread>]
    let main args =
        Initializer.AccessWindowsAppSDK ()

        do FSharp.Maui.WinUICompat.Program.Main(args, typeof<MauiExample.App.WinUI.App>)
        0
  1. Add a launch profile to run it unpackaged
"Run App": {
  "commandName": "Project"
}
  1. Run the project with a debugger attached

Expected
The app launches as it did in step 2

Actual
An exception is thrown

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Runtime.InteropServices.COMException (0x80004005): Unspecified error

   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at WinRT.BaseActivationFactory._ActivateInstance[I]()
   at WinRT.ActivationFactory`1.ActivateInstance[I]()
   at Microsoft.UI.Xaml.Controls.XamlControlsResources..ctor()
   at System.RuntimeType.CreateInstanceOfT()
   --- End of inner exception stack trace ---
   at System.RuntimeType.CreateInstanceOfT()
   at System.Activator.CreateInstance[T]()
   at Microsoft.Maui.Platform.ResourceDictionaryExtensions.AddLibraryResources[T](ResourceDictionary resources)
   at Microsoft.Maui.Hosting.MauiAppBuilder.MauiCoreInitializer.<Initialize>g__SetupResources|0_1()
   at Microsoft.Maui.Hosting.MauiAppBuilder.MauiCoreInitializer.Initialize(IServiceProvider services)
   at Microsoft.Maui.Hosting.MauiAppBuilder.Build()
   at MauiExample.App.MauiProgram.CreateMauiApp()
   at MauiExample.App.WinUI.App.CreateMauiApp()
   at Microsoft.Maui.MauiWinUIApplication.OnLaunched(LaunchActivatedEventArgs args)
   at Microsoft.UI.Xaml.Application.Microsoft.UI.Xaml.IApplicationOverrides.OnLaunched(LaunchActivatedEventArgs args)
   at ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(IntPtr thisPtr, IntPtr args)

OS: Windows 10

@TimLariviere
Copy link
Member

TimLariviere commented Jul 9, 2023

@0x0309 Thanks for the report.
Unfortunately the FSharp.Maui.WinUICompat package is in itself more of a workaround than a proper library.
Its goal is to allow basic F# WinUI apps to run, and does not cover all cases.

Also, I don't have much knowledge of WinUI. The workaround logic was mostly done by @PureWeen. I only packaged it for simpler use with Fabulous. And F# WinUI is not really a priority given Microsoft itself doesn't plan any F# support.

If you or someone else are motivated to investigate the issue, I'll be happy to review the PR and release a new package for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants