question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Private.CoreLib.dll

See original GitHub issue

Description

After getting a ‘Congratulations, everything looks great’ from MAUI check and going file -> new -> .NET MAUI App in VS 16.11.0 Preview 1.0, project will not run due to the error message An unhandled exception of type System.Reflection.TargetInvocationException occurred in System.Private.CoreLib.dll Exception has been thrown by the target of an invocation.

Steps to Reproduce

  1. Install VS Preview 16.11.0 Preview 1.0
  2. Install / Run MAUI check, getting green all the way down, and ending with ‘Congratulations, everything looks great!’
  3. Open VS Preview, go to file -> new -> .NET MAUI App
  4. Add https://aka.ms/maui-preview/index.json as a nuget package source
  5. Set the target to WinUI3
  6. Click Run
  7. Observe error window entitled ‘Exception Unhandled’, contents: System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation. Inner Exception: COMException: Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
  8. Observe contents of Output window stating An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Private.CoreLib.dll Exception has been thrown by the target of an invocation.

Expected Behavior

Default template app would run

Actual Behavior

Exception described above occurs

Basic Information

  • Version with issue: 6.0.100-preview.4.21255.9
  • Last known good version: N/A
  • IDE: VS 16.11.0 Preview 1.0
  • W10Pro 21H1 19043.985
  • MAUI nuget versions 6.0.100-preview.4.634

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

3reactions
Nyaosocommented, May 31, 2021

I have resolved the problem as follows:

Right Click on the Packaging project and set as startup-project;

Steps to Reproduce

  1. Install VS Preview 16.11.0 Preview 1.0
  2. Install / Run MAUI check, getting green all the way down, and ending with ‘Congratulations, everything looks great!’
  3. Open VS Preview, go to file -> new -> .NET MAUI App
  4. Add https://aka.ms/maui-preview/index.json as a nuget package source
  5. Set the target to WinUI3 (Package) <== RIGHT CLICK AND SET AS STARTUP PROJECT
  6. Ensure the Target is LOCAL MACHINE
  7. Click Run
3reactions
Nyaosocommented, May 31, 2021

I am having the same problem.

My environment is : Windows 10 Enterprise 20H2 Build 19042.985 Visual Studio Enterprise 2019 Preview Version 16.11.0 Preview 1.0

DOTNET 6 Preview SDK and Runtimes: 6.0.100-preview.4.21255.9 Microsoft.AspNetCore.App 6.0.0-preview.4.21253.5 Microsoft.NETCore.App 6.0.0-preview.4.21253.7 Microsoft.WindowsDesktop.App 6.0.0-preview.2.21154.2 Microsoft.WindowsDesktop.App 6.0.0-preview.4.21254.5

This is what is logged in the Windows Event Viewer

Application: MauiSample.WinUI3.exe CoreCLR Version: 6.0.21.25307 .NET Version: 6.0.0-preview.4.21253.7 Description: The process was terminated due to an unhandled exception. Exception Info: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Runtime.InteropServices.COMException (0x80040154): Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)) at WinRT.BaseActivationFactory…ctor(String typeNamespace, String typeFullName) in Microsoft.WinUI.dll:token 0x6000023+0x6e at Microsoft.UI.Xaml.Application._IApplicationStatics…ctor() in Microsoft.WinUI.dll:token 0x60135ef+0x1c at System.RuntimeType.CreateInstanceOfT() in System.Private.CoreLib.dll:token 0x6000632+0x3e — End of inner exception stack trace — at System.RuntimeType.CreateInstanceOfT() in System.Private.CoreLib.dll:token 0x6000632+0x4e at System.Activator.CreateInstanceT in System.Private.CoreLib.dll:token 0x6000950+0x0 at WinRT.WeakLazy`1.get_Value() in Microsoft.WinUI.dll:token 0x6000019+0x20 at Microsoft.UI.Xaml.Application._IApplicationStatics.get_Instance() in Microsoft.WinUI.dll:token 0x60135f0+0x0 at Microsoft.UI.Xaml.Application.Start(ApplicationInitializationCallback callback) in Microsoft.WinUI.dll:token 0x600917b+0x0 at MauiSample.WinUI.Program.Main(String[] args) in MauiSample.WinUI3.dll:token 0x6000011+0x21

Read more comments on GitHub >

github_iconTop Results From Across the Web

'System.Reflection.TargetInvocationException' occurred in ...
The event is probably raised before the elements are fully loaded or the references are still unset, hence the exceptions.
Read more >
Why I'm getting System.Reflection.TargetInvocationException
Why I'm getting System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.
Read more >
'System.Reflection.TargetInvocationException' in mscorlib.dll
These exceptions are not thrown in Visual Studio 2017. What are they and why are they shown? Is it a setting? My project...
Read more >
What is System.Private.CoreLib.dll and why is it giving me ...
When I run the build from visual studio I get an error message in the ... System.Private.CoreLib.dll is the main runtime library on...
Read more >
Upgrade: An exception of type 'System.Reflection ...
Upgrade: An exception of type 'System.Reflection.TargetInvocationException' occurred and was caught. Upgrade: An exception of type 'System.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found