Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

c# - 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:

enter image description here

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...