C# - VS Code - launch:program ... does not exist - c#

I am trying to debug a simple "Hello world" application in VS Code, however, when I press Ctrl + F5, it gives me the following error:
If I manually change the path in launch.json from:
${workspaceFolder}/bin/Debug/insert-target-framework-here/insert-project-name-here.dll
To:
"${workspaceFolder}/bin/Debug/netcoreapp2.1/test.dll"
It does work, however before it was working fine without me manually typing the path. Also, I have noticed that VS Code no longer asks to rebuild assets like it did before:
So far I have tried the following:
Uninstalled VS Code, then .NET Core 2.1, deleted the VS Code extension folder from %USER%\.vscode\ , re-installed VS Code, then .NET Core 2.1, and then the C# extension (C# for Visual Studio Code (powered by OmniSharp)).
When the VS Code starts, it does download the "OmniSharp" package successfully, but still, no prompt to rebuild assets when I open a C# file. Debugging gives the same issue as before.
Here is the launch.json:
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
}
And the tasks.json:
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet build",
"type": "shell",
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}

I found a solution that worked for me.
My VS Code was giving me the same error message, and what I did to fix it was:
- Press the combination Ctrl + Shift + P
- Restart Omnisharp
- Then it asks if you want to add missing files for build.
- Click Yes.
After this I was able to debug my app.
Hope it works for you!

Visit your \bin\Debug\netcoreapp3.1 in your project folder (That you open in VS)
Go to launch.json file in VS:
Replace:
"program": "${workspaceFolder}/bin/Debug//.dll",
With:
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/CSharp.dll",
In may case, the project is called CSharp. Watch out.

I had a the same error. The debugger was looking for the .dll file in ${workspaceFolder}/bin/Debug/netcoreapp3.1/myApp.dll but the file was located in ${workspaceFolder}/bin/MCD/Debug/netcoreapp3.1/tradeAppl.dll
After changing the launch.json file to read
...
"program": "${workspaceFolder}/bin/MCD/Debug/netcoreapp3.1/tradeAppl.dll",
...
I was able to debug the application without any problems.

Since you have :".dll" taged with "<" and ">", it means that you have give it a value.
The easiest way to do it is to open the project in VSCode and use find&replace to replace the:
with your project name which I do believe its: "test" as per the .dll name

Configure your Launch.json like this Gist
And there is no need to Tasks.json , you can Press F5 to build or configure it your self to which command should be run in default shell when you press F5

// "program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/csharp_multi_threads.dll",
You need to change the program value as it reminded

I switched to MS Visual Studio, since I did not find any other solutions.

-Right Click on Project Name And Click on Reveal in Explorer
-Copy Url In Explorer After Folder Name
For Example My Folder Address is
D:\IOT\Projects\LWSIOT_WebApiWM2\LWSIOT_WebApiWM2\LWSIOT_WebApiWM2\bin\Debug\netcoreapp3.1\LWSIOT_WebApiWM2.dll
And In Launch.json :
${workspaceFolder}/LWSIOT_WebApiWM2/LWSIOT_WebApiWM2/bin/Debug/netcoreapp3.1/LWSIOT_WebApiWM2.dll
-Paste in Launch.json on "Program":"<Your_Address>"
-Click On Debug And Its OK

In launch.json , replace :
"program": "${workspaceFolder}/Api/bin/Debug/netcoreapp3.1/Api.dll",
with:
"program": "${workspaceFolder}/Api/bin/linux/Debug/netcoreapp3.1/Api.dll"
Since I was running code in Linux machine so I should have provided Linux Folder' path

Must be an issue with the path to the dll in the program property of the launch.json file.
In my case, it still contained the old .net core framework version after the version upgrade.

Related

How to debug dotnet core source code using Visual Studio Code

I would like to explore the source code of dotnet when debugging my application, for example. I would like to hit F11 on the Where Linq method and see step by step what is happening at runtime.
I am aware that this is possible using Visual Studio (https://github.com/dotnet/core/issues/897), and in Rider it is enabled by default, and stepping into it is as easy as debugging my own code.
What it the easiest way to set this up in visual studio code and is it even possible?
Please note, this is NOT a duplicate of Is there anyway to debugging .NET Core source code by Visual Studio Code? as that is regarding simple debugging in VSCode, not stepping into the BCL.
Yes, it's possible.
Two links that were already mentioned by you are valuable but there is one more link https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
First, check 'launch.json' configuration file
{
"version": "0.2.0",
"configurations": [
{
"name": "example name",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/app/bin/Debug/net6.0/app.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false,
"justMyCode": false, // should be false, as we want to debug 3rd party source code
"requireExactSource": false, // https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#require-exact-source
"suppressJITOptimizations": true, // it's better to set true for local debugging
"enableStepFiltering": false, // to step into properties
"symbolOptions": {
"searchMicrosoftSymbolServer": true, // get pdb files from ms symbol server
"searchNuGetOrgSymbolServer": true,
"moduleFilter": {
"mode": "loadAllButExcluded",
"excludedModules": []
}
},
"logging": { // you can delete it if all is ok
"moduleLoad": true,
"engineLogging": true,
"trace": true
}
}
]
}
After you start debugging the 'DEBUG CONSOLE' will contain log like this
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.10\System.Private.CoreLib.dll'. Symbols loaded.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.10\System.Console.dll'. Symbols loaded.
If there was a problem with loading some pdbs you can use dotPeek, as local symbol server.
After that you can use 'Step Into (F11)' button in debug panel at vscode to debug .net source code.

Visual Studio Code cannot debug program

I am trying to use the C# extension in VS code to debug a program, however when I try to run without debugging I get the message "Cannot launch program setting the 'outFiles' attribute might help".
My launch.json file
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}
My C# code
using System;
// Class declaration
class Geeks {
// Main Method
static void Main(string[] args) {
}
}
As noted in comments you are using the launch.json for a Node project.
The Visual Studio Code C# extension can generate the assets you need to build and debug.
You can generate them through the Command Palette (View > Command Palette) by typing '.NET', and running .NET: Generate Assets for Build and Debug. This command will generate the necessary launch.json and tasks.json configuration files (under the .vscode folder).
See docs and debugging

can't debug project in omnisharp, even with DebugType=portable or embedded

I have a .csproj file that I'm unable to debug in VS Code with Omnisharp. Specifically, when I try to debug it, it complains
WARNING: Could not load symbols for '[assembly name].dll'. 'C:\Git\[project]\[assembly name]\bin\Debug\net472\[assembly name].pdb' is a Windows PDB. These are not supported by the cross-platform .NET Core debugger.
Loaded 'C:\Git\[project]\TestRunner\bin\Debug\net472\[assembly name].dll'. Cannot find or open the PDB file.
But I've set my DebugType to portable. My .csproj file looks like this:
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<VS_INSTALL_DIR Condition=" '$(VS_INSTALL_DIR)' == '' ">C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional</VS_INSTALL_DIR>
<LangVersion>8.0</LangVersion>
<NullableContextOptions>enable</NullableContextOptions>
<!-- NullableContextOptions was renamed to Nullable, and as of 2019-07-30, dotnet build supports one and Visual Studio supports the other.
We should delete NullableContextOptions when we can -->
<Nullable>enable</Nullable>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<DocumentationFile>bin\$(Configuration)\net472\$(AssemblyName).XML</DocumentationFile>
<NoWarn>1591;1573</NoWarn>
<!-- warns when a public member is missing an XML comment, warns when some params have XML comments and others don't -->
<DebugType>portable</DebugType>
<EmbedAllSources>true</EmbedAllSources>
<DebugSymbols>true</DebugSymbols>
<Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>
I've also tried <DebugType>embedded</DebugType>, and deleting my obj and bin folders, but I get the exact same message, except it looks for the PDB in the obj folder instead of the bin folder. After building I can see a PDB in the obj folder but not in the bin folder (expected because it should be embedded in the DLL), and it seems Omnisharp tries to load the obj/ PDB instead of the embedded one. And I guess the one in the obj folder is in the "full" PDB format?
(I initially did not have the EmbedAllSources or DebugSymbols settings, but saw a SO post that made me think they might be necessary. I've tried it without those settings with the same result.)
If it's relevant, it's a mixed C#/F# solution, and I can load the symbols for the F# code and the other C# projects in the solution just fine. Every single project in the solution has the DebugType set.
Edit:
Here's my launch.json and tasks.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Launch (console)",
"type": "clr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/TestRunner/bin/Debug/net472/TestRunner.exe",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
]
}
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"TestRunner/TestRunner.fsproj"
],
"problemMatcher": "$msCompile"
}
]
}

VisualStudio Code csharp debugger generating error

I recently upgraded my version of VisualStudio Code to the latest release and am I getting an error when trying to debug csharp applications. I am running in windows 10 (14393) and am using vs code 1.23.1. I have an application that I created a few months ago using visual studio code and at the time it was working fine. it is a MVC application that uses dotnetcore2.0. When I try to run debugging I get a message "command 'csharp.coreclrAdapterExecutableCommand' not found. I can execute the application by running "dotnet run" from the project folder.
I tried creating a new blank console application that just says "hello world" and again am able to run from "dotnet run" but when I try to debug I get the same message. I am able to run the build task successfully.
I tried to reseaerch the method mentioned in the error but can find little to nothing about it. I believe that omnisharp is the solution that the csharp debug runs in and I looked it up. From their documentation it says that it needs .net framework 4.6 to work. I verified that I have the sdk and runtime for each .net framework installed.
I am usually pretty good at figuring things like this out and this is my very first post on stack. I am hoping that someone might know what the heck this is so that I can move forward.
It would be good to note that I have tried to reboot my machine several times and even uninstalled/reinstalled vs code. An example of the launch.json file is below.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/helloworld/bin/Debug/netcoreapp2.0/helloworld.dll",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
Thanks to #bman7716 I was able to figure out what was going on. The issue was the omnisharp extension was corrupted (or a related dependency). I was able to resolve the issue by:
Uninstalling the c# extension from VS Code
Close VS Code
remove all C:\Users{username}.vscode\extensions\ms-vscode.csharp-{version}
Open VS Code
Install C# extension
Open Project
Go to Debug mode and start debug
This forced VS Code to re-install omnisharp and its dependencies and things worked just fine afterwards.

Some file not served when run via Visual Studio Code

I have a 'Hello World' Kestrel server generated by Yeoman (as described here).
yo aspnet
When I run the site via the command line everything work well:
dotnet run
If it's run through Visual Studio Code though bootstrap.css, jquery.js and bootstrap.js don't load (404).
Looking at the F12 tools, they are actually coming from different locations. When run via dotnet run they come from https://ajax.aspnetcdn.com/..., but when run through Visual Studio Code the browser is looking for them in a local folder ~/lib/....
a. Why are the files being sourced differently depending on how I run the site?
b. How do I fix this?
Thanks
When you run it from command line, it runs in production mode (no ASPNETCORE_ENVIRONMENT variable set. When you run it from Visual Studio it sets the ASPNETCORE_ENVIRONMENT to Development.
Inside your Razor files, you have a <environments> section which controls which files are served in which production mode. Depending on your environment/OS, you need to set the variable differently. i.e. in Linux you'd need to run ASPNETCORE_ENVIRONMENT=Development dotnet run.
As for the reason why you get 404 when running in development mode, you probably need to copy over the wwwroot folder to your output directory, with this entry in your project.json.
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"copyToOutput":
[
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
Though usually it should be necessary to add wwwroot to copyToOutput

Categories