21

I'm very new to Visual Studio Code. I'm trying to debug an application that exists already that I've cloned via Git. None of my files are modified yet. I've downloaded the microsoft extension "C# for Visual Studio Code (powered by OmniSharp)". The application starts and it brings me to the home page (http://localhost:5000/). However it didn't stop at my breakpoints within startup.cs

When I look at the application while its running instead of being a red bullet point its a hollow gray breakpoint. Hovering over it tells me "The source code is different from the original version. To allow this breakpoint to be hit: Add "requireExactSource":false to launch.json and restart debugging.". I can't understand this.

I'm using:

  • Visual Code 1.17.1
  • Shell 1.7.7
  • renderer 58.0.3029.110
  • node 7.9.0
  • architecture x64

I'm also using dotnet version 1.0.3

Sniipe
  • 1,116
  • 3
  • 13
  • 28

8 Answers8

65

This happened to me when I upgraded my project from .NET Core 2.0 to 2.1. The problem was that I forgot to edit launch.json to change the binary path from netcoreapp2.0 to netcoreapp2.1 so VS Code was looking for binaries in the wrong place. Editing the path fixed the problem.

EDIT: I suggest VS Code team to adopt a variable-based approach to fix this issue completely, like having something like $TargetRuntime in the path instead of something hardcoded like netcoreapp2.1 etc.

Sedat Kapanoglu
  • 46,641
  • 25
  • 114
  • 148
  • 2
    In my case I added RuntimeIdentifier to my csproj. VSCode was not able to locate the correct binaries. Thanks for your hint into the right direction! – Jeremi Nov 08 '19 at 17:55
  • 2
    This answer is still relevant for upgrading from .NET Core 5.x to .NET Core 6.0. A little more detail about the `launch.json`: the line to change is `"configurations"` -> `"program"` – Mycah Mar 16 '22 at 19:29
2

This could happen for several reasons, in my case it was a simple/dumb mistake, I created a solution in my main folder, then I added a new folder and created a webapp in it. I configured launch.json and task.json and it worked fine until I tried to debug a modification.

My problem was that I forgot to add the webapp project to the solution, so it failed when the solution tried to build it.

So the solution for me was to add my project to the solution.

If this is not your case try to figure out why your project is not being built, or why it is pointing to other directory.

marcos.borunda
  • 1,486
  • 1
  • 17
  • 34
2

This is a follow up to the accepted answer on the occasion of upgrading a razor web app from .Net Core 3.0 to 3.1:

  1. Change the .csproj file /Project/PropertyGroup/TargetFramework to netcoreapp3.1
  2. as earlier mentioned: change the launch.json configurations[0].program to workspaceFolder/bin/Debug/netcoreapp3.1/MyApp.dll
  3. Delete the netcoreapp3.0 and netcoreapp3.1 folders from workspaceFolder/bin/Debug/
  4. in the terminal: dotnet build
  5. F5 to debug and breakpoint gets hit
Andrew Cowenhoven
  • 2,778
  • 22
  • 27
1

I am kind of new with Visual Studio Code as well and I faced the same issue. Luckily, I was able to sort it out.

First of all, while I was in Debug mode Visual Studio Code gave me the right hint, which is the one that you mentioned:

Breakpoint warning: The source code is different from the original version. To allow this breakpoint to be hit: Add '"requireExactSource": false' to launch.json and restart debugging. -

So, in order to understand, I suggest you read thisVisualStudioCode-LaunchConfigurations

As the documentation in the link above states:

The launch.json file located in a .vscode folder in your workspace (project root folder) or in your user settings or workspace settings.

So, if you edit that file and do what the debug hint explains, that's:

Add '"requireExactSource": false' to launch.json and restart debugging. -

My launch.json now looks like this:

configurations": [
    {
        "name": ".NET Core Launch (web)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        // If you have changed target frameworks, make sure to update the program path.
        "program": "${workspaceFolder}/DotNetCoreAngularAPp/bin/Debug/netcoreapp2.1/DotNetCoreAngularApp.dll",
        "args": [],
        "cwd": "${workspaceFolder}/DotNetCoreAngularAPp",
        "stopAtEntry": false,
        "requireExactSource": false,

The last line shows the statement added. Now, you should be able to debug it. I hope this help.

Sebastian Inones
  • 1,561
  • 1
  • 19
  • 32
  • 4
    in this case, debugging itself can be useless because you might be debugging an out-of-date binary. OP should focus on the root cause behind the discrepancy instead. – Sedat Kapanoglu Aug 15 '18 at 18:55
  • @SedatKapanoglu I agree with you but as the original question states: >None of my files are modified yet. Theoretically, It shouldn't exist a discrepancy between the source code and the binary as the files were not modified. So, even though the root cause it's not solved he's able to debug which is the main goal. In any case, as you said the root cause of the "discrepancy" should be faced. – Sebastian Inones Aug 16 '18 at 10:27
1

I was having this problem. Deleting all bin/ and obj/ folders then rebuilding didn't fix it. My launch.json binary path program: was my exact DLL.

What fixed it was modifying my .cs source file, and rebuilding. Something was out of date, maybe vscode autosave of the .cs file, or dotnet build had cached something somewhere else.

Carl Walsh
  • 6,100
  • 2
  • 46
  • 50
0

I was also facing the same issue, my issue were fixed just by doing these two steps. In menu "BUILD"

  1. "Clean Solution"
  2. "Rebuild Solution"
0

I was having this same issue. Check your configuration in .vscode/launch.json and identify the "preLaunchTask". Then open .vscode/tasks.json and make certain that task exists and its workspace target passed in "args" points to your project file. In my case I had two web projects but only one build task.

bteller
  • 23
  • 4
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/31249560) – Ethan Mar 16 '22 at 03:23
0

I have the same issue and after inspecting the lunch.json file I noticed that the program folder was pointing to:

// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net6.0/ShoppingCartApi.dll",

then I realized that updated the target framework to Net7.0, so the output folder of the project when I build was changed to: "${workspaceFolder}/bin/Debug/net7.0/ShoppingCartApi.dll"

After updating the lunch.json file with the new path, debugger started to work again.

// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net7.0/ShoppingCartApi.dll",