19

I have Microsoft Visual Studio Professional 2012 installed, version 11.0.60610.01 Update 3.

When debugging a c# (.cs) file Visual Studio gives me the following message when I try to set a breakpoint:

"A breakpoint could not be inserted at this location".

I get this message even when trying to set it on a line within a method. But in a .vb file for a Visual Basic app, I can set a breakpoint.

I am wondering if anyone has any suggestions to resolve this or if I need to reinstall visual studio.

Thanks

Sam Leach
  • 12,746
  • 9
  • 45
  • 73
user1408767
  • 677
  • 1
  • 8
  • 30

6 Answers6

17

Maybe I'm too late for this question but here it goes anyway,

  1. BUILD > Clean Solution
  2. BUILD > Build Solution
Kup
  • 882
  • 14
  • 31
7

I have encountered a similar issue and I resolved it by exiting Visual Studio and deleting the .suo file from my solution folder.

This file is recreated when you open the project again and it is not harmful to delete it.

The .suo is used for storing the layout of your solutions, the breakpoints you've set, the tabs you had open, etcetera. I am not sure why this worked but my logic was that Visual Studio thought I was trying to place a breakpoint in a location different to where I was actually placing it.

Amicable
  • 3,115
  • 3
  • 49
  • 77
  • Thanks for the response. I exited visual studio and then deleted the .suo file. But when I opened the solution again, it still gave me the same message when trying to set a breakpoint. – user1408767 Sep 25 '13 at 13:26
  • Ah well, it was worth a try. Hope you find a solution that works for you. – Amicable Sep 25 '13 at 13:27
  • @Kokodoko .suo is a hidden file. so you'll need to check that your file options to make sure they're bring displayed. – Amicable Mar 11 '15 at 10:20
4

I was finally able to find a solution for this. I had to do a repair on my Visual Studio 2012 instance through the control panel -> Programs and Features, right clicking on Microsoft Visual Studio Professional 2012, and selecting change. In the Visual Studio window I then selected repair.

As part of the repair process, I also had to download web deploy located here: http://www.microsoft.com/en-us/download/details.aspx?id=4148 and point the visual studio repair process to the .msi file when it said it couldn't find the web deploy package and could not download it from the internet.

I also had to implement the fix indicated in the following stackoverflow question: Plain C# Editor in Visual Studio 2012 (No intellisense, no indentation, no code highlighting)

Now I am able to debug applications as expected.

Community
  • 1
  • 1
user1408767
  • 677
  • 1
  • 8
  • 30
3

Well, sheesh...for people as dumb as me, here's one more thing to consider:

You can put breakpoints on the curly braces at the start or close of a method, and you can put breakpoints on any line that is doing something (e.g. assigning a value or calling a method). However, you can't put a breakpoint on a line that is only declaring a variable or otherwise "doing nothing."

E.g. I had a method:

public IEnumerable<SomeObject> GetList()
{
    int distance;
    var otherVar = SomeValue;
}

I was trying to put the breakpoint on the first line with int distance;, which is something that works fine in other IDEs, but that doesn't work in VS. I had to go up to the brace or down to the next line with the assignment in order to get the breakpoint to set.

5 minutes of my life wasted, that I'll never get back, trying to debug a non-issue ;-p

Kevin Nelson
  • 7,613
  • 4
  • 31
  • 42
1

VS 2017 I had this, I was missing an ; inside a for loop

Lord Darth Vader
  • 1,895
  • 1
  • 17
  • 26
  • I noticed the same too in VS 2017. Sometimes when I have compilation error (red squiggly lines), I'm unable to place any breakpoint too. But this happens very rarely though. – Nik A. Nov 08 '17 at 10:45
0

If there is no instructions to execute on a line, VS refuses to set a breakpoint an offers no reason. EG

string str; //Cannot set breakpoint
string str = ""; //Can set breakpoint
Alan
  • 302
  • 5
  • 22