title: Why is HashSet<T> attributed with MayLeakOnAbort, but Dictionary<K,V> not?
body: <p>I noticed when trying to code a CLR procedure for SQL Server that HashSet is not allowed due to being attributed with <code>[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]</code>. SQL Server CLR procedures do not allow the use of objects where <code>MayLeakOnAbort</code> is set. Okay, so there are some classes to avoid in CLR procedures, and maybe even think twice about using outside of CLR procedures. The strange thing is that <code>Dictionary&lt;K,V&gt;</code> is <em>not</em> similarly restricted. Now based on my understanding of what a HashSet is and what a Dictionary is, I expect that a Dictionary should have all the complexity of a Hashset and <em>then</em> some. Why is it, then, that Dictionary is not similarly restricted? I'm doing my "think twice about using <code>HashSet&lt;T&gt;</code>" and seriously considering using a Dictionary instead even though I'm not writing a CLR procedure and need nothing more than a collection that can be quickly tested for membership of a complex key (object reference for an object that has no comparison, hashing or equality interfaces defined). Am I better off using a Hashset or Dictionary? Is Hashset different in that it will allow the use of classes with no comparison or equality interfaces based purely on memory addresses or something which might be why a HashSet is less "clean"?</p>