Warning given when debugging source code in visual studio 2010

匆匆过客 提交于 2019-12-05 19:45:26

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

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!

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

You source code is not the same as on compiling time. You can stop, clean and rebuild your project.

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!