Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jonthysell opened this issue Mar 15, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@jonthysell
Copy link
Contributor

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

@jonthysell
Copy link
Contributor Author

jonthysell commented Mar 15, 2024

The issue appears to be that the JS debugger gets confused when you've got a non-JS project opened when you try to attach.

Debugging does work, the workaround is to just open VS 2022 (>= 17.9.3) without the app's solution file open (i.e. select "Continue without code") and then attach, everything will work fine.

@jonthysell jonthysell added Area: Debug Infrastructure Developer First Experience Issues that are going to be hit by a new developer as they first try out RNW Area: Developer Experience Scenario: Visual Studio labels Mar 15, 2024
@jonthysell jonthysell changed the title Unable to debug RNW app (Hermes Direct Debugging) with Visual Studio 2022 17.9.3 if the native solution is open Unable to debug RNW app (Hermes Direct Debugging) with Visual Studio 2022 (17.9.3) if the native solution is open Mar 15, 2024
@chrisglein chrisglein removed the Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) label Mar 18, 2024
@chrisglein chrisglein added this to the Next milestone Mar 18, 2024
@chrisglein chrisglein assigned vmoroz and unassigned jonthysell Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants