'Trying to debug my dotnet 5 WPF app and getting an error: "The target process exited without raising a CoreCLR started event."

This is dotnet 5 WPF app that was converted from a dotnet framework app using this tool from Microsoft.

The full error says

The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core. The program '[20316] MPRegWpf.exe' has exited with code -2147450740 (0x8000808c).

I am using Visual Studio 2019 16.11.5.

Here is the output of dotnet --info:

.NET SDK (reflecting any global.json):
 Version:   6.0.100-rc.2.21505.57
 Commit:    ab39070116

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22000
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\

Host (useful for support):
  Version: 6.0.0-rc.2.21480.5
  Commit:  6b11d64e7e

.NET SDKs installed:
  3.1.301 [C:\Program Files\dotnet\sdk]
  3.1.414 [C:\Program Files\dotnet\sdk]
  5.0.402 [C:\Program Files\dotnet\sdk]
  6.0.100-preview.5.21302.13 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.1.21463.6 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.2.21501.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Here is my .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <OutputType>WinExe</OutputType>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <UseWPF>true</UseWPF>
    <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
    <PublishSingleFile>true</PublishSingleFile>
  </PropertyGroup>
  <PropertyGroup>
    <ApplicationIcon>myPassLogoHeader.ico</ApplicationIcon>
  </PropertyGroup>
  <ItemGroup>
    <Resource Include="Assets\yk05.PNG" />
    <Resource Include="Assets\yk06.PNG" />
    <Resource Include="Assets\yk07.PNG" />
    <Resource Include="Assets\yk08.PNG" />
    <Resource Include="Assets\yk09.PNG" />
    <Resource Include="Assets\yk10.PNG" />
    <Resource Include="Assets\yk11.PNG" />
    <Resource Include="Assets\yk12.PNG" />
    <Resource Include="Assets\yubikey01.png" />
    <Resource Include="Assets\badge_or_mypass.png" />
    <Resource Include="Assets\MFA_bg_withKey.png" />
    <Resource Include="Assets\badge3.png" />
    <Resource Include="Assets\pBar_3.png" />
    <Resource Include="Assets\pBar_5.png" />
    <Resource Include="Assets\pBar_2.png" />
    <Resource Include="Assets\bye.png" />
    <Resource Include="Assets\mpLoad.gif" />
    <Resource Include="Assets\alert.png" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\MyPassEnrollment\MyPassEnrollment.csproj" />
  </ItemGroup>
  <ItemGroup>
    <WCFMetadata Include="Connected Services\" />
  </ItemGroup>
  <ItemGroup>
    <Resource Include="myPassLogoHeader.ico" />
    <Resource Include="FodyWeavers.xml">
      <SubType>Designer</SubType>
    </Resource>
    <Resource Include="myPassLogoChipOnly %281%29.ico" />
    <Resource Include="myPassLogoChipOnly.ico" />
    <Resource Include="Assets\myPassLogo.png" />
    <Resource Include="Assets\LivIT. LLNL.png" />
    <Resource Include="Assets\blueArrow.png" />
    <Resource Include="Assets\myPassLogoHeader.png" />
    <Resource Include="Assets\phone.png" />
    <Resource Include="Assets\check2.png" />
    <Resource Include="Assets\x2.png" />
    <Resource Include="Assets\yk13_2.png" />
    <Resource Include="Assets\yk15_2.PNG" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Archived Pages\" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="CommonServiceLocator">
      <Version>2.0.6</Version>
    </PackageReference>
    <PackageReference Include="ControlzEx">
      <Version>5.0.0</Version>
    </PackageReference>
    <PackageReference Include="Costura.Fody">
      <Version>5.6.0</Version>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Gu.Wpf.FlipView">
      <Version>2.0.2</Version>
    </PackageReference>
    <PackageReference Include="LLNL-MyPass">
      <Version>1.19.0</Version>
    </PackageReference>
    <PackageReference Include="MaterialDesignThemes">
      <Version>4.2.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting">
      <Version>5.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Toolkit">
      <Version>7.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Toolkit.Mvvm">
      <Version>7.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Win32.Registry">
      <Version>5.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Xaml.Behaviors.Wpf">
      <Version>1.1.37</Version>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="NLog.Config">
      <Version>4.7.10</Version>
    </PackageReference>
    <PackageReference Include="RestSharp" Version="106.13.0" />
    <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
    <PackageReference Include="System.ComponentModel.Composition" Version="5.0.0" />
    <PackageReference Include="System.DirectoryServices" Version="5.0.0" />
    <PackageReference Include="System.DirectoryServices.AccountManagement" Version="5.0.0" />
    <PackageReference Include="System.Reactive.Core">
      <Version>5.0.0</Version>
    </PackageReference>
    <PackageReference Include="System.Reactive.Linq">
      <Version>5.0.0</Version>
    </PackageReference>
    <PackageReference Include="Vanara.PInvoke.Security">
      <Version>3.3.10</Version>
    </PackageReference>
    <PackageReference Include="WpfAnimatedGif">
      <Version>2.0.0</Version>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <Compile Remove="Behaviors\PasswordBehaviors.cs" />
    <Compile Remove="Commands\SaveChangesCommand.cs" />
    <Page Remove="UI\UserControls\Auth\Styles.xaml" />
  </ItemGroup>
</Project>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source