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?
问题:
回答1:
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
回答2:
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!
回答3:
Do a Build -> Clean Solution, then Build -> Build Solution. Then try debugging again, ensuring the active config is debug.
回答4:
You source code is not the same as on compiling time. You can stop, clean and rebuild your project.
回答5:
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.
回答6:
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