简体   繁体   English

使用动态对象时的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. 到现在为止还挺好。

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.

相关问题 使用ViewBag时RuntimeBinderException - RuntimeBinderException when using ViewBag 在视图中访问动态匿名类型时的RuntimeBinderException - RuntimeBinderException when accessing dynamic anonymous type in view 尝试使用动态类型时RuntimeBinderException - RuntimeBinderException when trying to use dynamic type 将C#动态与COM对象一起使用会引发RuntimeBinderException,以记录已实现接口的方法 - Using C# dynamic with COM object throws RuntimeBinderException for documented method of implemented interface 为什么在调用方法时使用带动态的json.net获取RuntimeBinderException - Why do I get a RuntimeBinderException using json.net with dynamic when calling a method 带有动态对象的RuntimeBinderException调用公共静态方法TryParse - RuntimeBinderException with dynamic object calling public static method TryParse 为什么动态对象的分配会抛出RuntimeBinderException? - Why does the assignment from a dynamic object throw a RuntimeBinderException? 将JSON对象反序列化为动态类型,但获取RuntimeBinderException访问属性? - Deserialized JSON object to dynamic type but getting RuntimeBinderException accessing properties? 将int []传递给参数类型为动态的方法时发生RunTimeBinderException - RunTimeBinderException when passing int[] to method having parameter type dynamic C#动态-“ RuntimeBinderException” - C# Dynamic - “RuntimeBinderException”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM