从动态类型中抑制RuntimeBinderException消息 [英] Suppress RuntimeBinderException messages from dynamic types

查看:107
本文介绍了从动态类型中抑制RuntimeBinderException消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我开始使用私有的NuGet服务器来管理我的组织的内部库。这意味着为了进入我们自己的库中的代码,我需要在调试选项中禁用启用我的代码,因为我们不再直接引用这些项目。除了 ViewBag 之外,这是一个非常庞大的MVC项目,它使用动态类型和 ExpandoObjects 。对于动态类型的每一次使用,我得到两个 RuntimeBinderExceptions ,这是很多的。这似乎是从我读过的正常行为。正常它可能是有用的,但不是有用的。



我的第一个想法是在Debug-> Exceptions对话框中禁用这个特殊的exeption。在那里没有找到例外。我无法弄清楚能够直接参与到项目之外的任何方式,也不会因为这些例外而打开自己。 (以及我不想听到的各种其他低级框架例外,但这是迄今为止最大的罪犯)。



最好的方法是什么要处理这个问题?



编辑:这是问题。禁用启用我的代码如何阻止?



解决方案

需要尝试的几件事:


  1. 禁用启用我的代码禁用。

    使用[DebuggerStepThrough()]停止调试器评估代码 - 将其放在您的class(继承所有属性和方法上的属性)或只是将其放在特定的属性/方法上。

    如果需要调试某些东西,您仍然可以将断点放在您的代码中。 p>


  2. 如果您的问题是要隐藏输出窗口中记录的异常,因为您看不到发生了什么,那么也许你可能会关闭生成异常跟踪的特定TraceSource(通过代码或.config文件)的跟踪。


  3. 另一方面也许你正在返回匿名类型是您的例外的原因首先....尝试将它们变成ExpandoObjects


  4. 如果没有3实际上导致问题,另一种可能要使NuGet服务器看到内部(见上一个链接)。



    5。更新 - 其实我觉得可能这么简单。

    http://msdn.microsoft.com/en-us/library/tw4t258c.aspx

    使用添加按钮在公共语言运行时异常类型下添加新的异常,并将其调用Microsoft.CSharp.RuntimeBinder.RuntimeBinderException...然后只要确保Thrown和User-Handled没有勾选。


参考文献:




I've recently started using a private NuGet server to manage my organization's internal libraries. This means in order to step into our own code that is in a library, I need to disable "Enable Just My Code" in debugging options since we aren't referring to the projects directly any more. This is a pretty hefty MVC project that uses dynamic types and ExpandoObjects in addition to ViewBag. I get two RuntimeBinderExceptions for every single use of a dynamic type... which is a lot. This appears to be normal behavior from what I've read. Normal it may be, but useful it is not.

My first thought was to disable this particular exeption in the Debug-> Exceptions dialog. The exception is not to be found there. I can't figure out any way to be able to step outside the projects referenced directly, without also opening myself up to these exceptions. (And all manner of other low-level framework exceptions that I don't want to hear about, but this is the biggest offender by far).

What's the best way to deal with this?

Edit: This is the problem. How do I stop this with "Enable Just My Code" disabled?

解决方案

A couple of things to try:

  1. Keep "Enable Just My Code" disabled.

    Use [DebuggerStepThrough()] to stop the debugger evaluating the code - put this on "your" class (to inherit the attribute on all your properties and methods) or just put it on specific properties/methods.

    You can still put a breakpoint in "your" code if you need to debug something.

  2. If your problem is that you want to "hide" the exceptions being logged in your Output Window, because you can't see what is going on, then maybe you could perhaps switch off the tracing of the particular TraceSource (via code or a .config file) that is generating the exception tracing.

  3. On the other-hand maybe you are returning anonymous types, and that is the cause of your exceptions in the first place....try turning them into ExpandoObjects

  4. If no 3 is in fact causing the issue, an alternative might be to make "internals" visible to the NuGet Server (see last link).

    5. UPDATE- Actually I think it might be as simple as this.

    http://msdn.microsoft.com/en-us/library/tw4t258c.aspx

    use the Add button to add a new exception under the "Common Language Runtime Exceptions" Type and call it "Microsoft.CSharp.RuntimeBinder.RuntimeBinderException"...then just make sure Thrown and User-Handled are not ticked.

References:

这篇关于从动态类型中抑制RuntimeBinderException消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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