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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With