从动态类型中抑制RuntimeBinderException消息 [英] Suppress RuntimeBinderException messages from dynamic types
问题描述
ViewBag
之外,这是一个非常庞大的MVC项目,它使用动态类型和 ExpandoObjects
。对于动态类型的每一次使用,我得到两个 RuntimeBinderExceptions
,这是很多的。这似乎是从我读过的正常行为。正常它可能是有用的,但不是有用的。 我的第一个想法是在Debug-> Exceptions对话框中禁用这个特殊的exeption。在那里没有找到例外。我无法弄清楚能够直接参与到项目之外的任何方式,也不会因为这些例外而打开自己。 (以及我不想听到的各种其他低级框架例外,但这是迄今为止最大的罪犯)。
最好的方法是什么要处理这个问题?
编辑:这是问题。禁用启用我的代码如何阻止?
需要尝试的几件事:
-
禁用启用我的代码禁用。
使用[DebuggerStepThrough()]停止调试器评估代码 - 将其放在您的class(继承所有属性和方法上的属性)或只是将其放在特定的属性/方法上。
如果需要调试某些东西,您仍然可以将断点放在您的代码中。 p> -
如果您的问题是要隐藏输出窗口中记录的异常,因为您看不到发生了什么,那么也许你可能会关闭生成异常跟踪的特定TraceSource(通过代码或.config文件)的跟踪。
-
另一方面也许你正在返回匿名类型是您的例外的原因首先....尝试将它们变成ExpandoObjects
-
如果没有3实际上导致问题,另一种可能要使NuGet服务器看到内部(见上一个链接)。
5。更新 - 其实我觉得可能这么简单。
http://msdn.microsoft.com/en-us/library/tw4t258c.aspx
使用添加按钮在公共语言运行时异常类型下添加新的异常,并将其调用Microsoft.CSharp.RuntimeBinder.RuntimeBinderException...然后只要确保Thrown和User-Handled没有勾选。
参考文献:
-
为什么Microsoft.CSharp.RuntimeBinder.RuntimeBinderException如果调用方法是吗?
-
http://mohammedezzatawad.blogspot.co.uk/2012/05/runtimebinderexception-cannot-resolver.html
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:
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.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.
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
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:
Why a Microsoft.CSharp.RuntimeBinder.RuntimeBinderException if the invoked method is there?
http://mohammedezzatawad.blogspot.co.uk/2012/05/runtimebinderexception-cannot-resolver.html
Don't stop debugger at THAT exception when it's thrown and caught
Can DebuggerStepThrough be inherited into the automatically generated IEnumerable implementation?
这篇关于从动态类型中抑制RuntimeBinderException消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!