views:

1230

answers:

3

Here's an interesting puzzle.

I downloaded Snippet Compiler to try some stuff out, and wanted to write the following code:

using System;
using System.Collections.Generic;

public class MyClass
{
    public static void RunSnippet()
    {
     HashSet<int> h = new HashSet<int>();
    }
}

But the above code doesn't compile. I get:

"The type or namespace name 'HashSet' could not be found (are you missing a using directive or an assembly reference?)"

Clearly I'm not. It seems it can't find HashSet, yet it finds other types in the Systems.Collections.Generic namespace (e.g. List, SortedDictionary).

What's the explanation for this? Presumeably Snippet Compiler is just using the standard Framework compiler under the covers...

I would be interested to know why this doesn't work.

+3  A: 

Check what version of System.Core.dll Snippet Compiler is using.

FlySwat
Just downloaded and checked. Doesn't seem to include System.Core by default in Snippet Compiler Live Ultimate 2008 Super Secret Plus Plus Gold Edition with Enhanced Extra Stuff for Developers.... Adding the reference allows it to compile.
tvanfosson
ok. I was mostly kidding on the name.
tvanfosson
+3  A: 

is your reference use

Namespace: System.Collections.Generic

Assembly: System.Core (in System.Core.dll)

version 3.5?

Fredou
System.Collections is actually in System.Core.dll
FlySwat
just edited it ;-)
Fredou
A: 

Excellent - yep, that was the answer. I had to add System.Core.dll to the referenced assemblies.

Thanks!

Craig

Craig Shearer