Unable to cast HashSet<string> to IReadOnlyCollection<string>

Harsh Gupta's Avatar

Harsh Gupta

23 Apr, 2015 06:21 PM

Hi All,
We have some code like so `` var hashSet = new HashSet<string>(); var hash = (IReadOnlyCollection<string>)hashSet; <pre><code> This complies correctly however fails at runtime with an error like so System.InvalidCastException : Unable to cast object of type 'System.Collections.Generic.HashSet1[System.String]' to type 'System.Collections.Generic.IReadOnlyCollection`1[System.String]'

MSDN says they added this in 4.5 https://msdn.microsoft.com/en-us/library/bb359438(v=vs.110).aspx

Wondering if we do not have the right implementation dlls in build machines. I have a sample project at https://github.com/harshgMSFT/Scratch

Please let me know if we are doing something incorrectly.

  1. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 01:55 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac