microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.37k stars 682 forks source link

Debug Unpackaged Winui3 template project gets COMException Class not registered #10147

Closed ToolmakerSteve closed 1 week ago

ToolmakerSteve commented 1 week ago

Describe the bug

The template "Blank App, Packaged (WinUI 3 in Desktop)" should include needed references so that "Debug | AppName (Unpackaged)" can be run and debugged.

Failing that, Getting Started documentation should describe what references are needed, and how to add them explicitly to the project.

Failing that, I need to know how to discover what references are missing, so I can add them manually to bin folder.

Why I care:
Porting a large legacy .Net Framework project to Windows App SDK.
For developer productivity, it is essential that the project be debuggable without performing packaging.
Making and testing changes has always been very quick; any step that slows this down is a significant development cost.

I have no idea how to find and fix whatever is missing.

Steps to reproduce the bug

  1. New Project from template "Blank App, Packaged (WinUI 3 in Desktop)".

  2. Deploy Debug | x64 | AppName (Package) => success: "WinUI Desktop" window with button "Click Me" that works.

  3. Deploy Debug | x64 | AppName (Unpackaged)

RESULT:

System.Runtime.InteropServices.COMException
  HResult=0x80040154
  Message=Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
  Source=System.Private.CoreLib
  StackTrace:
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs:line 849
   at WinRT.ActivationFactory.Get(String typeName, Guid iid)
   at Microsoft.UI.Xaml.Application.get__objRef_global__Microsoft_UI_Xaml_IApplicationStatics()
   at Microsoft.UI.Xaml.Application.Start(ApplicationInitializationCallback callback)
   at WinUI3_20241109.Program.Main(String[] args) in C:\Users\toolm\source\repos\WinUI3_20241109\obj\x64\Debug\net8.0-windows10.0.19041.0\win-x64\App.g.i.cs:line 26

Line that fails:

global::Microsoft.UI.Xaml.Application.Start((p) => {
    var context = new global::Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext(global::Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread());
    global::System.Threading.SynchronizationContext.SetSynchronizationContext(context);
    new App();
});

NOTE: I did not find any way to see what class is "not registered".

Expected behavior

App launches, exactly the same as "AppName (Package)" does.

Screenshots

No response

NuGet package version

None

Windows version

Windows 11 (22H2): Build 22621

Additional context

VS Community 2022, 17.11.5

ToolmakerSteve commented 1 week ago

I was not following the correct documentation.

The doc I needed to follow is:
Create your first WinUI 3 (Windows App SDK) project / Unpackaged.

I was missing this step:

Add the following property to your project file ...

<WindowsPackageType>None</WindowsPackageType>