公共语言运行时无法设置断点
这实际上是这个问题的另一部分。
我正在 vs 2010 中远程调试 CRM 2011 插件。
在我的源文件之一中,除了少数地方之外,我可以在整个代码中设置断点。
当我尝试设置断点时出现此错误 “无法设置以下断点:”和“公共语言运行时无法设置断点。”
protected override void ExecutePlugin()
{
SetStateResponse response = new SetStateResponse(); // Breakpoint works
// Message switch
switch (_crmMessage) // Breakpoint error
{
case CrmPluginMessageEnum.Create:
Entity pimage = null; // Breakpoint error
if (_context.PostEntityImages.ContainsKey("postcreate")) // Breakpoint works
pimage = _context.PostEntityImages["postcreate"]; // Breakpoint error
break; // Breakpoint error
}
} // Breakpoint error
更新 此外,在模块窗口中,它将 dll 显示为“已优化”:“否” 用户代码:“是” 符号状态:“符号已加载”
This is actually another part of this question.
Error settings breakpoints but only on some lines while debugging
I'm remote debugging a CRM 2011 plugin in vs 2010.
I'n one of my source files I can set breakpoint all throughout the code except in a few places.
When I try to set a breakpoint I get this error
"The following breakpoint cannot be set:" and "The Common Language Runtime was unable to set the breakpoint."
protected override void ExecutePlugin()
{
SetStateResponse response = new SetStateResponse(); // Breakpoint works
// Message switch
switch (_crmMessage) // Breakpoint error
{
case CrmPluginMessageEnum.Create:
Entity pimage = null; // Breakpoint error
if (_context.PostEntityImages.ContainsKey("postcreate")) // Breakpoint works
pimage = _context.PostEntityImages["postcreate"]; // Breakpoint error
break; // Breakpoint error
}
} // Breakpoint error
UPDATE
Also, in the modules window it shows the dll as Optimized: No User Code: Yes Symbol Status: Symbols Loaded
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
两种可能性,已经被其他答案引用:
Release 版本,因为 Release 版本会删除或优化
你的代码。
在 Visual Studio 中部署程序集(在项目属性选项卡上)。
当您增加版本时,CRM一定会卸载旧的
程序集版本并重新加载新版本,无需重置 IIS。
Two possibilities, already kind of referenced by the other answers:
the Release build, because the Release build will remove or optimize
your code.
deploy the assemblies in Visual Studio (on project properties tab).
When you increment the version, CRM will be sure to unload the old
assembly version and reload the new one without an IIS reset.
当我在 Visual Studio 的两个实例中打开项目时,我遇到了同样的问题。我没有调试的项目锁定了该文件,并通知我“此文件已在源代码编辑器之外进行了修改”。接受非调试解决方案中的更改后,我不再收到错误,并且在我正在调试的解决方案中命中断点。
听起来这个错误有很多可能的原因,但这对我来说是这样。
I had this same issue when I had the project open in two instances of Visual Studio. The project which I was not debugging had a lock on the file and notifying me "This file has been modified outside of the source editor." After accepting the changes in my non-debugging solution, I no longer received the error and my breakpoints were hit in my solution I was debugging.
It sounds like there is a lot of possible causes to this error, but this did it for me.
当我使用
Ctrl+B
快捷键创建断点(参见附图)时,我遇到了这个问题,并且我输入了一个不存在的函数名称,因此添加了断点,但导致了错误。然后每次我启动该项目时都会出现该错误。解决方案:
我从断点列表中删除了断点(请参见附图的左下角),选择断点部分,然后选择该项目并单击删除。
如果您没有看到断点部分,
您可以通过按
Ctrl+Alt+B
I got this problem when I created a breakpoint using the
Ctrl+B
shortcut (see image attached), and I entered a name of a function which doesn't exist, so the breakpoint was added but caused an error. then each time I started the project it appeared that error.Solution:
I deleted the breakpoint from the breakpoints list (see left bottom in image attached), select the breakpoints section, then select the item and click delete.
If you don't see the breakpoints section
You can retrieve it by hitting
Ctrl+Alt+B
除了关于正在优化的 DLL 的更新之外,您所指出的断点不起作用的行可能会被优化掉,因为您的整个 switch 语句不会执行任何其他操作决定是否为从未使用过的变量分配值并且不会超出 switch 语句的范围。因此,编译器不会为 switch 语句生成任何代码,因为它根本不执行任何操作,或者 jit 只是出于同样的原因在运行时删除它。
Further to your update about the DLL being optimised the lines you have indicated where breakpoints don't work will likely be optimised away as your entire switch statement does not do anything other decide whether or not to assign a value to a variable that is never used and does not live beyond the scope of the switch statement. As such the compiler will simply not generate any code for the switch statement as it does not do anything at all or the jit just gets rid of it at run time for the same reason.
我刚刚有过类似的经历,我解决这个问题的方法是在调用例程的地方放置一个断点,然后单步执行例程,直到我准确地看到它认为它在做什么。就我而言,有一个返回阻止了例程中的所有代码运行,因此优化器将其全部丢弃。有时这是愚蠢的事情,对吗?无论如何,如果您从调用堆栈中的更高级别开始并进入问题所在的例程,则问题的原因可能会变得更加明显。
I just had a similar experience and the way I worked through it was to put a breakpoint at the spot where the routine was called and then single-stepped into the routine until I saw exactly what it thought it was doing. In my case, there was a return that was preventing all the code in the routine from running, so the optimizer tossed it all out. Sometimes it's the stupid things, right? Anyway, if you start at a level higher in the call stack and step into the routine where the problem is, the reason for the problem might become more obvious.
如果您正在针对 CRM 进行调试,我刚刚发现此问题的另一个原因是未更新插件注册点。即使您将新的 DLL 复制到目标计算机并远程附加到 DLL CRM 不会使用的进程。 CRM 将尝试从其数据库中获取旧版本的副本,直到您重新运行插件注册。
一个错误浪费了我一天半的时间!
Another cause of this issue I have just found if you are debugging against CRM is not updating the plugin registration points. Even if you copy the new DLLs to the target machine and attach remotely to that process that is not the DLL CRM will use. CRM will try to take a copy of an old version from its database until you rerun the plugin registrations.
An error which wasted a day and a half for me!
我在开始运行调试项目时遇到此错误,我通过清理所有项目和重建所有项目来解决它,重建后错误消失。
I got this error when start run debugging the project, and I solve it by Clean All Project and Rebuild All Project, after rebuild the error disappear.