Visual studio debugging issue with files of the same name

When I received a particular error message in Visual Studio 2008, I decided to investigate.

When debugging a web project in Visual Studio, I received a message stating that a specific breakpoint would not be hit: “The breakpoint will not currently be hit. The source code is different from the original version […]” As part of the solution, it suggests to unchecked “require source files to exactly match the original version” in the Visual studio IDE. This does not help.

The breakpoint is disconnected. The message indicates that the compiled code is not the same as the running version. Therefore, there is a mismatch that causes the breakpoint to be disconnected.

Before rebuilding the solution, I tried all the relevant proposed solutions I could find.

The only solution that worked:

I do not like to play with knives but the only thing that works involves editing the .csproj file itself. So, unload the project file, edit it by cutting and pasting the three asp.net files so that they are together in the ItemGroup. For example:

  <ItemGroup>

    <Content Include=”Default.aspx” />

    <Compile Include=”Default.aspx.cs”>

      <DependentUpon>Default.aspx</DependentUpon>

      <SubType>ASPXCodeBehind</SubType>

    </Compile>

    <Compile Include=”Default.aspx.designer.cs”>

      <DependentUpon>Default.aspx</DependentUpon>

    </Compile>

  </ItemGroup>

In most cases, when I clean and rebuild, the debugger goes to the correct code behind page. Sometimes this is insufficient if I have a least one file with the same name in different folder. In this case, Default.aspx:

<ItemGroup>

    <Content Include=”Book\Default.aspx” />

    <Compile Include=”Book\Default.aspx.cs”>

      <DependentUpon>Default.aspx</DependentUpon>

      <SubType>ASPXCodeBehind</SubType>

    </Compile>

    <Compile Include=”Book\Default.aspx.designer.cs”>

      <DependentUpon>Default.aspx</DependentUpon>

    </Compile>

  </ItemGroup>

In such a case, I copy the offending ItemGroup to a safe location. I then delete it from the .csproj file. This ensures that Visual Studio has no ambiguity over which Default.aspx.cs file to use. Of course, when I same finished debugging, I put copy the saved ItemGroup back into the .csproj file.

Proposed solutions that did not work

If this does not help then try examining some of the other propose solutions. These are the proposed solutions that did not work but were useful in isolating the issue. Be careful when mixing and match these proposed solution. Nonetheless, none of these worked:

  • Clean solution
  • Ensure IIS is pointing to the correct physical path
  • Stop IIS site (if applicable)
  • Recycle IIS App Pool (if applicable)
  • Start IIS site (if applicable)
  • Reset the hosting application (iis or what have you)   
  • Ensure you are in debug mode
  • Ensure there are no Debug attributes on the code that prevent code from being debugged, such as DebuggerHidden or DebuggerStepThrough, at any point of the application
  • Ensure that .pdb files are in the same folder as the executable you are running and ensure the last modified date of both files match, and that VS is attached to that exe (and no other).
  • Ensure that optimisation is switched off in Debug mode. [Project / Properties, Build settings tab]
  • Delete its obj and bin folders
  • Delete local TFS or SVN repository and get it from source control from scratch
  • Delete the temporary ASP.NET generated assembly files for the project under “C:\WINDOWS\Microsoft.NET\Framework{framework version}\Temporary ASP.NET Files”
  • Uninstall and reinstall Visual Studio (try to avoid)