RuntimeBinderException当使用动态对象时 [英] RuntimeBinderException when using dynamic object

查看:139
本文介绍了RuntimeBinderException当使用动态对象时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我在这里缺少一些明显的东西,所以请随便指出我。



我有一个简单的单元测试来说明我的问题: / p>

  [测试] 
public void DynamicTest()
{
dynamic myDynamic = new ExpandoObject );
myDynamic.Prop =abc;
Assert.AreEqual(abc,myDynamic.Prop);
}

当我执行单元测试时,它通过。如果我选择调试单元测试(所有CLR异常在VS中的Debug - > Exceptions下勾选),我看到一个RuntimeBinderException:





它不是致命的,所以我可以点击F5并继续,测试仍然通过,但这似乎是错误的。我在这里做错了吗?在我们的应用程序的一般使用期间,它非常烦人地得到这些例外。或者我应该忽略RuntimeBinderException的框,并忽略这个?

解决方案

您正在设置调试器,当CLR异常<强>抛出(即第一次机会)不未处理(即第二次机会)。显然,你可以取消这个,它会消失,但是如果你想从你的代码中看到第一次机会的例外,那么你可以启用 Just My Code选项。只要启用我的代码,调试器只有通过代码才会破坏第一次机会异常。这些选项不会影响应用程序对用户的行为,只是调试器在附加时执行的操作。


I feel like I'm missing something obvious here so feel free to point it out to me.

I have a simple unit test to illustrate my problem:

        [Test]
    public void DynamicTest()
    {
        dynamic myDynamic = new ExpandoObject();
        myDynamic.Prop = "abc";
        Assert.AreEqual("abc",myDynamic.Prop);
    }

When I execute the unit test it passes. So far so good.

If I choose to debug the unit test (with all CLR exceptions ticked under Debug -> Exceptions in VS) I see a RuntimeBinderException:

Its not fatal, so I can hit F5 and continue and the test still passes but this seems wrong. Am I doing something wrong here? Its pretty annoying getting these exceptions during general use of our application. Or should I just untick the box for RuntimeBinderException and ignore this?

解决方案

You are setting the debugger to break when CLR exceptions are thrown (i.e. first-chance) not unhandled (i.e. second-chance). Obviously, you can untick this and it will go away, but if you want to see first-chance exceptions only from your code, then you can enable the Just My Code option. With Just My Code enabled the debugger will only break on a first-chance exception if it passes through your code. These options don't affect the behavior of your application for a user, only what the debugger does when attached.

这篇关于RuntimeBinderException当使用动态对象时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆