What goes in the “Non-Public members” node in Visual Studio's Watch window?

我的梦境 提交于 2020-01-13 18:01:28

问题


I assumed that all Non-Public (ie, private, protected, internal, and internal protected) members of C# objects go under "Non-Public Members" when I look at objects in Visual Studio's Watch Window. But then, I noticed an anamoly with this code:

   class HashDerived : System.Security.Cryptography.HashAlgorithm { ... }

   HashAlgorithm hash1 = new HashDerived();
   HashAlgorithm hash2 = new System.Security.Cryptography.SHA1Cng();

hash1's "Non-Public Members" looks like this:

whereas hash2's "Non-Public Members" looks like this:

So it seems like for hash1, only the private field (m_bDisposed) appears under the "Non-Public members" node, where for hash2, even protected and protected internal members like "HashSizeValue" and "HashValue" appear in it.

Why does this happen? What are the rules behind this behaviour?


回答1:


The behavior you are seeing here is a bug. The C# debugger shouldn't be showing static members in this scenario. I confirmed this with the current owner of the code base and he's going to file a bug for the next release of Visual Studio.

The specific scenario under which this happens is

  • Just My Code is enabled
  • The type is defined in what's determined to be a non-user assembly
  • The type of the reference and object instance are different (switch hash2 to SHA1Cnf and the problem disappears)

Note there may be other scenarios where this appears. This is the behavior I was able to narrow down in the debugging / experimentation that I did.



来源:https://stackoverflow.com/questions/11594725/what-goes-in-the-non-public-members-node-in-visual-studios-watch-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!