Skip to content

Unpackaged Fabulous Maui app crashes at startup #3

Open
@0x0309

Description

@0x0309

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions