Skip to content

Unable to debug RNW app (Hermes Direct Debugging) with Visual Studio 2022 (17.9.3) if the native solution is open #12842

Open
@jonthysell

Description

@jonthysell

Problem Description

If you have an RNW app and you open the .sln file (loading the native vcxproj app project in Visual Studio 2022) then you'll get an error when trying to debug the JS by attaching to Metro at http://localhost:8081 as recommended by the debugging docs:

Trying to attach:
image

The error:
image

Added logging after calling DebugAdapterHost.Logging /On /OutputWindow in the Command Window:

 1> DebugAdapterHost version: 17.6.10907.1 commit:6fef36f95dd1139788bfdde4ba25a71b4ccdc1aa
 1> [JavaScriptDebuggerExtensions] About to compile the list of startup projects for the source mapper's internal cache.
 1> [JavaScriptDebuggerExtensions] Succesfully compiled the startup projects' list for the source mapper's internal cache: C:\code\test73\windows\test73\test73.vcxproj
 1> [JavaScriptDebuggerExtensions] About to compile the list of all loaded projects for the source mapper's internal cache.
 1> ERROR: [JavaScriptDebuggerExtensions] Get file path of project for logging purposes failed due to: System.NotImplementedException: Not implemented (Exception from HRESULT: 0x80004001 (E_NOTIMPL))
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.VisualStudio.WebClient.Diagnostics.URLToFilePathMapper.GetMkDocumentForProject(IVsProject project, UInt32 itemId)
   at Microsoft.VisualStudio.WebClient.Diagnostics.URLToFilePathMapper.PopulateMultipleProjectToFilePathsMapping(IEnumerable`1 projects):
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.VisualStudio.WebClient.Diagnostics.URLToFilePathMapper.GetMkDocumentForProject(IVsProject project, UInt32 itemId)
   at Microsoft.VisualStudio.WebClient.Diagnostics.URLToFilePathMapper.PopulateMultipleProjectToFilePathsMapping(IEnumerable`1 projects)
 1> ERROR: [JavaScriptDebuggerExtensions] Get file path of project for logging purposes failed due to: System.NotImplementedException: The method or operation is not implemented.
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.VisualStudio.WebClient.Diagnostics.URLToFilePathMapper.GetMkDocumentForProject(IVsProject project, UInt32 itemId)
   at Microsoft.VisualStudio.WebClient.Diagnostics.URLToFilePathMapper.PopulateMultipleProjectToFilePathsMapping(IEnumerable`1 projects):
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.VisualStudio.WebClient.Diagnostics.URLToFilePathMapper.GetMkDocumentForProject(IVsProject project, UInt32 itemId)
   at Microsoft.VisualStudio.WebClient.Diagnostics.URLToFilePathMapper.PopulateMultipleProjectToFilePathsMapping(IEnumerable`1 projects)
 1> [JavaScriptDebuggerExtensions] Succesfully compiled the list of all loaded projects for the source mapper's internal cache: C:\code\test73\windows\test73\test73.vcxproj, C:\code\test73\node_modules\react-native-windows\Folly\Folly.vcxproj, C:\code\test73\node_modules\react-native-windows\fmt\fmt.vcxproj, C:\code\test73\node_modules\react-native-windows\ReactCommon\ReactCommon.vcxproj, C:\code\test73\node_modules\react-native-windows\Chakra\Chakra.vcxitems, C:\code\test73\node_modules\react-native-windows\Microsoft.ReactNative\Microsoft.ReactNative.vcxproj, C:\code\test73\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems, C:\code\test73\node_modules\react-native-windows\Common\Common.vcxproj, System.__ComObject@56760589, C:\code\test73\node_modules\react-native-windows\Shared\Shared.vcxitems, C:\code\test73\node_modules\react-native-windows\Mso\Mso.vcxitems, C:\code\test73\node_modules\react-native-windows\include\Include.vcxitems, [Shared MSBuild Project Files], Microsoft.VisualStudio.CommonIDE.Solutions.ProjectSystems.MiscellaneousFilesProject@44895264
 1> ERROR: Failed to parse launch configuration JSON.

NullReferenceException: Object reference not set to an instance of an object.

Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.Utilities.DteWorkspacePathProvider.MatchesNodeUrl(Project project, String url)
System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.Utilities.DteWorkspacePathProvider.WorkspaceRoot(CdpDebugTargetDescriptor descriptor, Boolean appendWwwRoot)
Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.PineZorro.LaunchConfiguration.ExtractAttachConfiguration(IAdapterLaunchInfo launchInfo, IWorkspacePathProvider workspacePathProvider, ILogger logger)
Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.PineZorro.LaunchConfiguration.FromLaunchInfo(IAdapterLaunchInfo launchInfo, IWorkspacePathProvider workspacePathProvider, ILogger logger)
Microsoft.VisualStudio.WebClient.Diagnostics.AdapterLauncher.<>c__DisplayClass37_0.<UpdateLaunchOptions>b__0(ITelemetryReporter reporter)
Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.Telemetry.TelemetryReporterFactory.ReportOperation(TelemetryNamespace telemetryNamespace, String entityName, String eventDescription, Action`1 operationToReport, Boolean isUserTask)
Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.Telemetry.TelemetryReporterFactory.ReportUserTask(String entityName, String eventDescription, Action`1 operationToReport)
Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.AdapterHosting.DebugAdapterHostFactory.CreateDebugAdapterHost(ConfigurationWrapper configuration, IDiagnosticLogger log, ExtensibilityManager extensibilityManager, IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop, Boolean registerStandardHandlers, DebugProtocolOptions options, Action`1 syncRequestErrorHandler)

 1> ERROR: Unexpected error

DebugAdapterLaunchException: Failed to launch debug adapter.  Additional information may be available in the output window.

Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.AdapterHosting.DebugAdapterHostFactory.CreateDebugAdapterHost(ConfigurationWrapper configuration, IDiagnosticLogger log, ExtensibilityManager extensibilityManager, IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop, Boolean registerStandardHandlers, DebugProtocolOptions options, Action`1 syncRequestErrorHandler)
Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.AdapterHosting.DebugAdapterHostFactory.CreateDebugAdapterHost(DebuggedProcess process, IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop)
Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.Engine.Implementation.DebuggedProcess.StartDebugAdapter(IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop)

Failure Location: ReadingConfiguration
Inner Exception: 
    NullReferenceException: Object reference not set to an instance of an object.

Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.Utilities.DteWorkspacePathProvider.MatchesNodeUrl(Project project, String url)
System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.Utilities.DteWorkspacePathProvider.WorkspaceRoot(CdpDebugTargetDescriptor descriptor, Boolean appendWwwRoot)
Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.PineZorro.LaunchConfiguration.ExtractAttachConfiguration(IAdapterLaunchInfo launchInfo, IWorkspacePathProvider workspacePathProvider, ILogger logger)
Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.PineZorro.LaunchConfiguration.FromLaunchInfo(IAdapterLaunchInfo launchInfo, IWorkspacePathProvider workspacePathProvider, ILogger logger)
Microsoft.VisualStudio.WebClient.Diagnostics.AdapterLauncher.<>c__DisplayClass37_0.<UpdateLaunchOptions>b__0(ITelemetryReporter reporter)
Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.Telemetry.TelemetryReporterFactory.ReportOperation(TelemetryNamespace telemetryNamespace, String entityName, String eventDescription, Action`1 operationToReport, Boolean isUserTask)
Microsoft.VisualStudio.WebClient.Diagnostics.HtmlToolHost.Telemetry.TelemetryReporterFactory.ReportUserTask(String entityName, String eventDescription, Action`1 operationToReport)
Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.AdapterHosting.DebugAdapterHostFactory.CreateDebugAdapterHost(ConfigurationWrapper configuration, IDiagnosticLogger log, ExtensibilityManager extensibilityManager, IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop, Boolean registerStandardHandlers, DebugProtocolOptions options, Action`1 syncRequestErrorHandler)

 1> ERROR: Failed to launch debug adapter.  Additional information may be available in the output window.

Object reference not set to an instance of an object.

This repros with a RNW 0.73 app using Hermes and direct debugging with Visual Studio 17.9.3. Extracted from #12113.

Steps To Reproduce

Create and build new app with Hermes and Direct Debugging enabled

  1. npx react-native@latest init test73
  2. cd test73
  3. npx react-native-windows-init --overwrite
  4. Change UseWebDebugger to false and UseDirectDebugger to true in windows\test73\App.cpp
  5. npx react-native run-windows --logging

Try to attach Visual Studio debugger

  1. Open Visual Studio 2022 (Node.js development support installed) and open the solution file windows\test73.sln
  2. Open Debug > Attach to Process
    a. Connection type: JavaScript and TypeScript (Chrome DevTools/V8 Inspector)
    b. Connection target: https://127.0.0.1:8081
    c. Attach to: JavaScript and TypeScript
  3. Click Attach

Expected Results

Debugger attaches, loads the source map from Metro, and lets me debug the JS code.

CLI version

12.3.6

Environment

info Fetching system and libraries information...
System:
  OS: Windows 11 10.0.22631
  CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  Memory: 2.97 GB / 15.84 GB
Binaries:
  Node:
    version: 18.16.1
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.19
    path: C:\Program Files (x86)\Yarn\bin\yarn.CMD
  npm:
    version: 9.5.1
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    AllowAllTrustedApps: Enabled
    Versions:
      - 10.0.19041.0
      - 10.0.22000.0
      - 10.0.22621.0
IDEs:
  Android Studio: Not Found
  Visual Studio:
    - 17.9.34701.34 (Visual Studio Enterprise 2022)
Languages:
  Java: Not Found
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.6
    wanted: 0.73.6
  react-native-windows:
    installed: 0.73.10
    wanted: 0.73.10
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Target Platform Version

None

Target Device(s)

Desktop

Visual Studio Version

Visual Studio 2022

Build Configuration

Debug

Snack, code example, screenshot, or link to a repository

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions