I had set breakpoint in source code but it will give me warning that source code is different from original one. It will not hit breakpoint.Hit location to allow change in source code. can anybody explain me waht is problem?

- 98,240
- 88
- 296
- 433

- 1,055
- 7
- 21
- 41
-
Are you using any AOP framework? ie PostSharp? – MattDavey Jan 19 '12 at 13:38
-
1winform framework but which is again wrapped in formframework which is our own – Abhijit Shelar Jan 19 '12 at 13:41
-
Clean the code but still has problem The source file is different when module was built. Module is dll file. It ask would you like the debugger to use it anyway? yes or no? – Abhijit Shelar Jan 19 '12 at 13:46
-
Are you running a Debug or Release build configuration? Release build could cause problems where the compiler is optimizing away chunks of code.. – MattDavey Jan 19 '12 at 13:48
6 Answers
Checksum of source code file doesn't match checksum into the PDB file.
To solve that rebuild the solution.
Workaround: In Location property of a breakpoint check Allow source code to be different

- 98,240
- 88
- 296
- 433
This can happen when you compile & run a release build. In Release builds the compiler makes optimizations that may change or delete portions of code, take this example:
static void Main()
{
int x = 10 + 5; // <---- BREAKPOINT HERE
Console.WriteLine("Foo");
}
If you compile & run that code in a debug build, the breakpoint will be hit as usual. In a release build, the compiler will see that 'x' is never used, and will "optimize away" the entire line, which means the breakpoint will never be hit!

- 8,897
- 3
- 31
- 54
Do a Build -> Clean Solution, then Build -> Build Solution. Then try debugging again, ensuring the active config is debug.

- 3,769
- 4
- 31
- 34
You source code is not the same as on compiling time. You can stop, clean and rebuild your project.

- 60,192
- 27
- 155
- 202
I had this issue when I had a class library in one solution and a web project in another solution. While stepping through code in the websolution, it stepped into my class library. This caused the class library files to be opened in my web solution.
My problem occurred when I changed some code in my class library. As normal I did a build on both projects in the correct order. However, i would get the message saying the source code was different. This was because I had the older "view" of the class files still open in my web solution caused by the following option having been turned off.
Options > Environment > Detect when file is changed outside the environment
Closing the class files in my web project solved my problem. I am now changing that option.
Hope this helps someone.

- 24,169
- 25
- 107
- 177
The above suggestions didn't work for me when running unit tests--I was performing a clean and rebuild for the whole solution but the DLL and PDB files were not being deleted in the ~\UnitTests\bin\Debug directory, so I had to manually delete those files, then right-click on the UnitTests directory and choose "Build."
Please note that in my case I am using Visual Studio 2013 with update 3.
UPDATE:
Ended up creating a batch file to clean and build my solution, so that Visual Studio does not incorrectly leave certain project without rebuilding them:
msbuild.exe "MyClassLibrary\MyClassLibrary.csproj" /t:Rebuild /p:Configuration=Debug
msbuild.exe "UnitTests\UnitTests.csproj" /t:Rebuild /p:Configuration=Debug

- 6,929
- 6
- 66
- 79