Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调试时错误设置断点,但仅在某些行上_C#_.net_Visual Studio 2010_Clr_Dynamics Crm 2011 - Fatal编程技术网

C# 调试时错误设置断点,但仅在某些行上

C# 调试时错误设置断点,但仅在某些行上,c#,.net,visual-studio-2010,clr,dynamics-crm-2011,C#,.net,Visual Studio 2010,Clr,Dynamics Crm 2011,此行导致PostEntityImages集合中出现“找不到键” Entity pimage = _context.PostEntityImages["postcreate"]; 当我把一个断点放在那条线上,并把它放在手表的窗口里,它工作正常,而且钥匙还在 更新: protected override void ExecutePlugin() { try { Entity pimage = null; if (_context.PostEntityImages.Contains

此行导致
PostEntityImages
集合中出现“找不到键”

Entity pimage = _context.PostEntityImages["postcreate"];
当我把一个断点放在那条线上,并把它放在手表的窗口里,它工作正常,而且钥匙还在

更新:

protected override void ExecutePlugin()
{

try
{
    Entity pimage = null;
    if (_context.PostEntityImages.ContainsKey("postcreate"))
        pimage = _context.PostEntityImages["postcreate"];
}
catch (Exception)
{
    // Never hits this line
    throw;
}
} // When stepping in/over the line assigning pimage, execution will jump to this point, then be caught in the catch block of this methods caller.
更新#2:

protected override void ExecutePlugin()
{

try
{
    Entity pimage = null;
    if (_context.PostEntityImages.ContainsKey("postcreate"))
        pimage = _context.PostEntityImages["postcreate"];
}
catch (Exception)
{
    // Never hits this line
    throw;
}
} // When stepping in/over the line assigning pimage, execution will jump to this point, then be caught in the catch block of this methods caller.

在调试模式下,某些断点设置良好。其他人给出错误“无法设置以下断点:”

您描述的断点和单步行为通常是由于试图在“发布”生成配置中调试项目而导致的。在这两种情况下,您很可能会遇到编译器优化了代码行的情况,因为它们是无关的

例如,如果您有以下代码:

try
{
  throw new ArgumentNullException("foo");
}
catch
{
  var x = 0;
  throw;
}
上面的
catch
块是无用的,编译器的流分析足够聪明,可以确定它可以安全地进行优化。如果在运行这样一个优化的构建时单步执行代码,它将直接跳过异常处理程序并跳转到调用方的异常处理程序。设置断点也会产生奇怪的错误,特别是当您试图在程序已经调试时在优化的外线上设置断点时

在调试、非优化的构建中,编译器将保留那些本来毫无意义的语句(例如,将值赋给一个永远不再使用的变量),特别是因为它们是有用的调试工具


确保您正在使用的任何构建配置都没有在项目的“构建”属性中设置“优化代码”复选框。请注意,配置的名称对VS来说毫无意义——如果将项目的构建配置命名为“Debug”,但启用了优化,则会得到一个不可调试的构建。

是否检查了大写字母和小写字母的拼写?康纳斯基回来干什么?true,false?此外,在调试器中检查变量值可能会触发其他代码,例如在使用后期绑定时。我同意,大小写将是我的首选。@MBen_context.PostEntityImages.ContainsKey(“postcreate”)返回true。我直接从“代码”窗口复制到“监视”窗口中。因此,也许您应该尝试这样做:PostEntityImages.TryGetValue(“postcreate”,out entity)@谢谢你的提示。我处于调试模式,未选中优化代码。只有1个部分不能设置断点,上面和下面的行都可以。