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?
-
Are you using any AOP framework? ie PostSharp?MattDavey– MattDavey2012-01-19 13:38:18 +00:00Commented Jan 19, 2012 at 13:38
-
1winform framework but which is again wrapped in formframework which is our ownAbhijit Shelar– Abhijit Shelar2012-01-19 13:41:30 +00:00Commented Jan 19, 2012 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– Abhijit Shelar2012-01-19 13:46:58 +00:00Commented Jan 19, 2012 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– MattDavey2012-01-19 13:48:11 +00:00Commented Jan 19, 2012 at 13:48
6 Answers
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!
Comments
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.
Comments
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