[英]Microsoft Visual Studio 2012 cannot set breakpoint in c# file
I have Microsoft Visual Studio Professional 2012 installed, version 11.0.60610.01 Update 3. 我安装了Microsoft Visual Studio Professional 2012,版本11.0.60610.01更新3。
When debugging ac# (.cs) file Visual Studio gives me the following message when I try to set a breakpoint: 调试ac#(。cs)文件时,当我尝试设置断点时,Visual Studio会给出以下消息:
"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.
但是在Visual Basic应用程序的.vb文件中,我可以设置断点。
I am wondering if anyone has any suggestions to resolve this or if I need to reinstall visual studio. 我想知道是否有人有任何建议来解决这个问题,或者我是否需要重新安装visual studio。
Thanks 谢谢
Maybe I'm too late for this question but here it goes anyway, 也许我对这个问题来说太迟了但是无论如何它仍然存在,
I have encountered a similar issue and I resolved it by exiting Visual Studio and deleting the .suo
file from my solution folder. 我遇到了类似的问题,我通过退出Visual Studio并从我的解决方案文件夹中删除
.suo
文件来解决它。
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. .suo
用于存储解决方案的布局,您设置的断点,打开的选项卡等。 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. 我不确定为什么会这样,但我的逻辑是Visual Studio认为我试图在与我实际放置它的位置不同的位置放置一个断点。
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.
我必须通过控制面板 - >程序和功能,右键单击Microsoft Visual Studio Professional 2012,然后选择更改,对我的Visual Studio 2012实例进行修复。 In the Visual Studio window I then selected repair.
在Visual Studio窗口中,我选择了修复。
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. 作为修复过程的一部分,我还必须下载位于此处的Web部署: http : //www.microsoft.com/en-us/download/details.aspx?id = 4148 ,并将visual studio修复过程指向。 msi文件,它说它无法找到Web部署包,无法从互联网上下载。
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) 我还必须实现以下stackoverflow问题中指示的修复: Visual Studio 2012中的Plain C#Editor(没有intellisense,没有缩进,没有代码突出显示)
Now I am able to debug applications as expected. 现在我能够按预期调试应用程序。
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 (eg 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."
但是,您不能在仅声明变量或“无所事事”的行上放置断点。
Eg 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;
我试图将断点放在
int distance;
的第一行int distance;
, which is something that works fine in other IDEs, but that doesn't work in VS. ,这在其他IDE中运行良好,但在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
我浪费了5分钟,我永远不会回来,试图调试非问题
;-p
VS 2017 I had this, I was missing an ; VS 2017我有这个,我错过了; inside a for loop
在for循环中
If there is no instructions to execute on a line, VS refuses to set a breakpoint an offers no reason. 如果没有指令要在一行上执行,VS拒绝设置一个没有理由的断点。 EG
例如
string str; //Cannot set breakpoint
string str = ""; //Can set breakpoint
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.