Re: Where is System.Collections when using csc.exe



"Marco Shaw" <marco.shaw@xxxxxxxxxxxxxxxxxx> wrote in message news:urXfmsS$HHA.5160@xxxxxxxxxxxxxxxxxxxxxxx
I've got some C# code to create a custom PowerShell cmdlet with these statements:

...
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
...

My compile fails using csc.exe:
PSH> csc /t:library /r:$ref testweather2.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.1378
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

testweather2.cs(65,13): error CS0246: The type or namespace name 'Collection' could not be found (are you missing a
using directive or an assembly reference?)

The "Collection" type is in the System.Collections.ObjectModel namespace which is part of the mscorlib assembly, this assembly is implicitely referenced, so above should work.

testweather2.cs(69,13): error CS1579: foreach statement cannot operate on variables of type
'Collection<System.Management.Automation.PSObject>' because 'Collection<System.Management.Automation.PSObject>'
does not contain a public definition for 'GetEnumerator'
PSH>

PSH> $ref
C:\WINDOWS\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
You should not reference assemblies in the GAC, the PS assemblies (like System.Management.Automation.dll)
should be found in "x:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0", where x is your system drive. So you need to add a reference to x:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll).


So I'm figuring I need to add a couple of references. I'm assuming I need to go and find the DLLs for:
1. System.Collections
2. System.Collections.Generic
3. System.Collections.ObjectModel

Are they normally hidden? I can't seem to find them.


This are namespaces, not assemblies, these namespaces are part of mscorlib.dll.

Visual Studio C# Express 2005 doesn't have a problem with them though, and can compile my code without errors.

That also brings up another point, if the path has spaces, I've not been able to figure out how to add a reference with spaces to csc.exe. Tried quotes, casting it to a string... I can't figure it out.


Paths containing spaces need to be enclosed by quotes, like : /r:"path containing spaces"


Willy.

.


Loading