Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Inconsistent behavior in a Visual Studio debug window or I am just not understanding how it works?

$
0
0

Running an installation of Visual Studio 2015 RC Community Edition on Windows 7 Ultimate. I've got a very basic MVC 5 application started that I used Microsoft's default template to get going.

I set a breakpoint in the debugger in /Controllers/Account/LogOff() action method. The breakpoint isn't all that relevant to my question but that's where I am.

So, I am looking at the "User" property in the "Locals" window and the "Type" is shown as an System.Security.Principal.IPrincipal which references an instance of a System.Security.Claims.ClaimsPrincipal. This object has a property called "Claims" which is shown as a childe node of the "User" object in the locals window.

But if you try to reference the "Claims" property in the intermediate window or the command window you get a response along the lines of:

>? User.Claims;
error CS1061: 'IPrincipal' does not contain a definition for 'Claims' and no extension method 'Claims' accepting a first argument of type 'IPrincipal' could be found (are you missing a using directive or an assembly reference?)

However, when I just issue the command of "? User" I get this information back:

{System.Security.Claims.ClaimsPrincipal}
Claims: {System.Security.Claims.ClaimsPrincipal.<get_Claims>d__1}
CustomSerializationData: null
Identities: Count = 1
Identity: {System.Security.Claims.ClaimsIdentity}
m_identities: Count = 1
m_serializedClaimsIdentities: null
m_userSerializationData: null
m_version: "1.0"

So, when used alone on the command line/intermediate window, the debugger treats the "User" reference as it's runtime type of System.Security.Claims.ClaimsPrincipal. But when you try to access properties on that same "User" reference, the debugger wants to go back to treating "User" as the type it was declared as, which is a System.Security.Principal.IPrincipal and the request to see the "Claims" property fails.

How does Visual Studio determine the default way to treat any given object in the command line/intermediate window? Is it by declared type? Is it by runtime type? Or is it contextual depending on whether you want to view the object itself or a property which it has? So far, my observations point to the latter remark.


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>