Can I view the runtime structure of a dynamic in .Net?
I just ran across an interesting error caused by a misconfiguration in my application, and it prompted this question.
The Error in Question
I am working on an ASP.Net MVC 3 web application, and I had accidentally dragged the web.config file into itself from solution explorer, resulting in the following in web.config:
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="trueD:\Projects\app_base\src\WebApp.UI\Web.config"/>
</appSettings>
What was happening was that this configuration caused the ViewContext object to be corrupted (and rightly so); I got the following when the MVC runtime tried to access it (this from the immediate window)
? ViewContext.ClientValidationEnabled
'ViewContext.ClientValidationEnabled' threw an exception of type 'System.FormatException'
base {System.SystemException}: {"String was not recognized as a valid Boolean."}
My Question
Is there a way to look at the contents of memory for a dynamic
in the DLR? In this case, I'd like to see the contents of the memory location that is referenced to parse ClientValidationEnabled
, but every time I tried to access the value, the开发者_Python百科 runtime automatically attempted to box it into a bool
. I got as far as
((dynamic)((dynamic)this).ViewContext).ClientValidationEnabled
before I gave up trying to figure out a QuickWatch way to do it.
精彩评论