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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With