Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor Hot Reload Debugging Using VSCode

I want to debug with hot reload enabled using VSCode. I keep getting this error after I made some changes:

BadImageFormatException: Bad IL range. OTPHub.Pages.Counter..ctor()

TargetInvocationException: Exception has been thrown by the target of an invocation. System.RuntimeType.CreateInstanceDefaultCtor(bool publicOnly, bool wrapExceptions)

It seems that there is a problem with the hot reloaded built assembly.

Here is my launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Core Launch (web)",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "dotnet",
      "args": [
        "watch",
        "--project",
        ".",
        "--verbose"
      ],
      "cwd": "${workspaceFolder}/OTPHub",
      "stopAtEntry": false,
      "serverReadyAction": {
        "action": "openExternally",
        "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceFolder}/Views"
      }
    },
    {
      "name": ".NET Core Attach",
      "type": "coreclr",
      "request": "attach"
    }
  ]
}

Should change something from this launch.json setting? How can I debug it with hot reload enabled?

like image 800
Alvin Stefanus Avatar asked Oct 19 '25 15:10

Alvin Stefanus


1 Answers

Basically removed cwd and added specific project file path as I had multiple projects in my workspace.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Core Launch (web)",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "dotnet",
      "args": [
        "watch",
        "--project",
        "./Project/Project.csproj", //IMPORTANT: give .csproj file path relative to workspace root
        "--verbose"
      ],
      "stopAtEntry": false,
      "serverReadyAction": {
        "action": "openExternally",
        "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceFolder}/Views"
      }
    },
    {
      "name": ".NET Core Attach",
      "type": "coreclr",
      "request": "attach"
    }
  ]
}

Inspiration: @MrC aka Shaun Curtis

like image 191
IsmailS Avatar answered Oct 21 '25 07:10

IsmailS