RuntimeBinderException当使用动态对象 [英] RuntimeBinderException when using dynamic object
问题描述
我觉得我缺少明显的东西在这里可以随意点出来给我。
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.
如果我选择调试单元测试(与调试下打勾所有的CLR异常 - >在VS例外),我看到一个RuntimeBinderException:
If I choose to debug the unit test (with all CLR exceptions ticked under Debug -> Exceptions in VS) I see a RuntimeBinderException:
它不是致命的,所以我可以按F5继续,测试还通过但这似乎是错误的。难道我做错了什么吗?一般使用我们的应用程序在其pretty的烦人让这些异常。或者我应该只是勾去掉了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?
推荐答案
正在设置调试器打破时,CLR例外是抛出(即第一次机会)没有未处理(即第二次机会)。很明显,你可以勾去掉这一点,它会消失,但如果你想看到第一次机会异常只能从code,那么你就可以启用的只是我的code选项。只有我的code启用调试器将打破只在第一次机会异常,如果它通过你的code。这些选项不会影响对用户应用程序的行为,只是有什么调试程序时附后。
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屋!