[英]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.
到现在为止还挺好。
If I choose to debug the unit test (with all CLR exceptions ticked under Debug -> Exceptions in VS) I see a RuntimeBinderException: 如果我选择调试单元测试(在调试 - > VS中的异常下勾选所有CLR异常),我会看到一个RuntimeBinderException:
Its not fatal, so I can hit F5 and continue and the test still passes but this seems wrong. 它不是致命的,所以我可以击中F5继续并且测试仍然通过,但这似乎是错误的。 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?
或者我应该取消RuntimeBinderException的框并忽略它?
You are setting the debugger to break when CLR exceptions are thrown (ie first-chance) not unhandled (ie second-chance). 要设置调试器时CLR 抛出异常 (即第一次机会)没有未处理的 (即第二次机会)打破。 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 .
显然,您可以解开它并且它会消失,但如果您只想从代码中看到第一次机会异常,那么您可以启用Just My Code选项 。 With Just My Code enabled the debugger will only break on a first-chance exception if it passes through your code.
启用Just My Code后,如果调试器通过您的代码,它将只会在第一次机会异常时中断。 These options don't affect the behavior of your application for a user, only what the debugger does when attached.
这些选项不会影响应用程序对用户的行为,只会影响调试程序在附加时的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.