系统动态错误? [英] System.Dynamic bug?

查看:79
本文介绍了系统动态错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我玩C#4.0动态时,我发现这样的代码发生了奇怪的事情:

 使用系统。动态; 

密封类Foo:DynamicObject
{
public override bool TryInvoke(
InvokeBinder binder,object [] args,out对象结果)
{
result = new object();
返回true;
}

static void Main()
{
dynamic foo = new Foo();

var t1 = foo(0);
var t2 = foo(0);
var t3 = foo(0);
var t4 = foo(0);
var t5 = foo(0);
}
}

好的,它有效但...看看在IntelliTrace窗口中:



截图http:// img717。 imageshack.us/img717/4914/10435230.png



所以每次调用(和动态对象的其他操作)都会导致抛出并捕获奇怪的异常!



我明白,有时可能会使用异常机制进行优化,例如,首先调用动态可能会执行到一些stub委托,这只会引发异常 - 这可能是像一个信号到动态绑定器来解析正确的成员并重新指派代理。下一次调用相同的代理将执行没有任何检查。



但是...的代码行为看起来很奇怪。也许在DynamicObject上的任何操作中抛出和捕捉异常两次 - 是一个错误?

解决方案

谢谢,我打开了一个错误,我们正在看它。一旦我听到编译器团队的话,我会更新这个。它正在抛出C#运行时绑定(Microsoft.CSharp.dll)。



如果您在Debug.Exceptions中启用了第一次机会异常,那么您将按此。 IntelliTrace与错误无关,只是向您展示了抛出并吞下的第一次机会异常。


While I playing with the C# 4.0 dynamic, I found strange things happening with the code like this:

using System.Dynamic;

sealed class Foo : DynamicObject
{
    public override bool TryInvoke(
        InvokeBinder binder, object[] args, out object result)
    {
        result = new object();
        return true;
    }

    static void Main()
    {
        dynamic foo = new Foo();

        var t1 = foo(0);
        var t2 = foo(0);
        var t3 = foo(0);
        var t4 = foo(0);
        var t5 = foo(0);
    }
}

Ok, it works but... take a look at IntelliTrace window:

screenshot http://img717.imageshack.us/img717/4914/10435230.png

So every invokation (and other operations too on dynamic object) causes throwing and catching strange exceptions twice!

I understand, that sometimes exceptions mechanism may be used for optimizations, for example first call to dynamic may be performed to some stub delegate, that simply throws exception - this may be like a signal to dynamic binder to resolve an correct member and re-point delegate. Next call to the same delegate will be performed without any checks.

But... behavior of the code above looks very strange. Maybe throwing and catching exceptions twice per any operation on DynamicObject - is a bug?

解决方案

Thanks, I've opened a bug, we're looking at it. I'll update this once I hear from the Compiler team. It's throwing in the C# runtime binder (Microsoft.CSharp.dll).

If you enable first-chance exceptions in Debug.Exceptions, you will hit this. IntelliTrace has nothing to do with the bug, it's just showing you the first-chance exception being thrown and swallowed.

这篇关于系统动态错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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