Sniipe
Sniipe

Reputation: 1306

Visual Studio Code Breakpoint warning: The source code is different from the original version

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:

I'm also using dotnet version 1.0.3

Upvotes: 24

Views: 16947

Answers (11)

Fabricio
Fabricio

Reputation: 31

I have the same issue and after inspecting the launch.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",

Upvotes: 2

P S
P S

Reputation: 13

I was having same issue, however, mine was fixed when I change below files and .net version from .net7 to .net8

  • .vscode/settings.json
  • .vscode/task.json

It works after above change.

Note - I upgrade from .net7 to .net8 in my project file after that this issue started.

Upvotes: 0

hgiahuyy
hgiahuyy

Reputation: 308

**EXAMPLE .net3.1 upgrade to .net6.0 **

OPEN file .vscode/launch.json -> EDIT "netcoreapp3.1" to ".net6.0"

enter image description here

enter image description here

Upvotes: 0

Thibaut
Thibaut

Reputation: 39

In my case it happened with a net7.0 project for the reason below :

My final goal was to publish my application in a self contained and single file. I read the Microsoft .NET CLI documentation and in the section "MSBuild properties" :

PublishSingleFile

Packages the app into a platform-specific single-file executable. For more information about single-file publishing, see the single-file bundler design document.

We recommend that you specify this option in the project file rather than on the command line.

And for a single file result you must define a RuntimeIdentifier (c.f. dotnet single-file doc).

So... according to all this I added this to my csproj :

<PropertyGroup>
    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>true</SelfContained>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

By adding <RuntimeIdentifier>win-x64</RuntimeIdentifier>, the build output result changes from "bin{Configuration}{TargetFramework}" to "bin{Configuration}{TargetFramework}{RuntimeIdentifier}", eg. :

Before adding <RuntimeIdentifier>win-x64</RuntimeIdentifier>, output changes from bin\debug\net7.0 to bin\debug\net7.0\win-x64

After these csproj changes, if I keep modifing the source code and try debugging I obtain the warning "Breakpoint warning: The source code is different from the original version".

By cleaning all binairies and rebuiling the project I finally obtained an explaination : app

Finally, don't forget to modify launch.json / configurations / program from : "${workspaceFolder}/bin/Debug/net7.0/MyProject.dll" to "${workspaceFolder}/bin/Debug/net7.0/win-x64/MyProject.dll".

So imo, dotnet publish configuration should relate to publish operation only (the command) and not impact the project.

--

thank you for reading

Upvotes: 0

Sedat Kapanoglu
Sedat Kapanoglu

Reputation: 47680

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.

Upvotes: 72

bteller
bteller

Reputation: 23

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.

Upvotes: 0

Raja Rizwan
Raja Rizwan

Reputation: 1

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"

Upvotes: 0

Carl Walsh
Carl Walsh

Reputation: 6989

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.

Upvotes: 1

Andrew Cowenhoven
Andrew Cowenhoven

Reputation: 2816

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

Upvotes: 2

marcos.borunda
marcos.borunda

Reputation: 1486

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.

Upvotes: 2

Sebastian Inones
Sebastian Inones

Reputation: 1701

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.

Upvotes: 3

Related Questions