Home > Software design >  WinUI3 App Throws Exception - What Have I Missed?
WinUI3 App Throws Exception - What Have I Missed?

Time:09-17

I recently upgraded Visual Studio 2019 to install the Project Reunion templates so I can run WinUI3 apps. I followed this enter image description here

Here the details of my Visual Studio installation.

Microsoft Visual Studio Professional 2019

Version 16.11.3

VisualStudio.16.Release/16.11.3 31702.278

Microsoft .NET Framework

Version 4.8.04084

When I try to run an app, I get this error message:

System.Reflection.TargetInvocationException HResult=0x80131604 Message=Exception has been thrown by the target of an invocation. Source=System.Private.CoreLib StackTrace: at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor) at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions) at System.Activator.CreateInstanceT at WinRT.WeakLazy`1.get_Value() at Microsoft.UI.Xaml.Application._IApplicationStatics.get_Instance() at Microsoft.UI.Xaml.Application.Start(ApplicationInitializationCallback callback) at App9.Program.Main(String[] args) in C:\Users\chris\source\repos\App9\App9\App9\obj\x64\Debug\net5.0-windows10.0.19041.0\App.g.i.cs:line 26

This exception was originally thrown at this call stack: [External Code]

Inner Exception 1: COMException: Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))

Installed Workloads:

enter image description here

enter image description here

The guide says to install C (v142) Universal Windows Platform tools. I see this in the installer:

enter image description here

enter image description here

CodePudding user response:

I've seen this type of exception being thrown when I've accidentally set the wrong project as the startup project in Visual Studio.

WinUI apps currently have two projects: the main app project and a packaging project (which generates an MSIX). To debug the WinUI app, you need to set the packaging project as the Startup Project.

Going forward, the team are working on merging the two for the most common scenarios. More complex scenarios may still require a packaging project. You can try out the single project using either of these Visual Studio extensions:

CodePudding user response:

Make sure that you have enabled the Developer Mode on your PC(Windows Settings > Update & Security > For developers > Developer Mode > On). And the extension: Project Reunion, make sure you has installed.

Then the issue should be related to the system or other things.

For Windows system

1). Try to use SFC tool to repair missing or corrupted system files.

2). Check if there is any error recorded for Windows Update, and use Windows Troubleshooter to fix them.

3). Try to update Windows.

For other things

1). Clear NuGet cache.

2). Restore NuGet Packages: right-click the solution > Restore NuGet Packages.

3). Repair Visual Studio 2019.

4). Delete .vs, bin and obj folders in your solution/project folder and then rebuild your solution and run it.

5). Disable antivirus software temporary and reboot your machine then try again.

6). Change the Configuration to x86 and run again.

  • Related