I have an object coming from .Net that has a property of type SyncHashTable that can't be viewed w/o an exception being thrown.
One-line repro:
[HashTable]::Synchronized(@开发者_如何学Go{})
Multi-line easier to play with repro:
$ht = new-object hashtable
$ht.add("foo", "bar")
$hts = [Hashtable]::Synchronized($ht)
$hts
The error:
format-default : Object reference not set to an instance of an object.
+ CategoryInfo : NotSpecified: (:) [format-default], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.FormatDefaultCommand
Anyone have any insight into this?
Got word back from Microsoft that this can be made to work:
PS> $r = [hashtable]::Synchronized(@{})
PS> $r|format-table -expand coreonly -autoSize
Count IsReadOnly IsFixedSize IsSynchronized SyncRoot Keys Values
----- ---------- ----------- -------------- -------- ---- ------
0 False False True System.Object {} {}
PS> $r.Add("key","value")
PS> $r["key"]
value
Apparently it is a bug in the way the type is formatted for display.
精彩评论