Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where did HashSet<T> go in VS2012?

I recently installed VS2012. A C++ project (with .Net 4.0) that compiles fine under VS2010 is not recognizing HashSet<T> on VS2012. I even tried being explicit with following declaration:

System::Collections::Generic::HashSet< String^ >^ _reasons;

But that only results in the error:

error C2039: 'HashSet' : is not a member of 'System::Collections::Generic

The documentation says it's in System.Collections.Generic. The C++ compiler doesn't think so.

Any ideas on where it went?

like image 390
Rob R Avatar asked Nov 26 '12 18:11

Rob R


1 Answers

HashSet<> was a late addition to .NET, it became available in .NET 3.5. The namespace is older, mscorlib.dll contained classes in System::Collections::Generic since .NET 2.0, classes like Stack<> and Queue<>. HashSet<> got added in a new assembly for .NET 3.5, System.Core.dll, they didn't want to tinker with the 2.0 assemblies.

Accordingly, you must add a reference to System.Core to avoid the error message.

Always refer back to the MSDN documentation when you get an error like this, it shows you want assembly reference is required.

like image 158
Hans Passant Avatar answered Oct 25 '22 01:10

Hans Passant