471,305 Members | 1,132 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

Where is System.Collections when using csc.exe

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:
PSHcsc /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?)
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.Aut omation\1.0.0.0__31bf3856ad364e35\System.Managemen t.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.

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.

--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
Sep 22 '07 #1
3 15916
Marco,

Namespaces are not required to have their types completely contained
within an assembly, so asking where the types for a namespace are located
doesn't make much sense.

However, the Collection<Tclass is in mscorlib.dll. By default, csc
should make a reference to mscorlib.dll automatically, so it seems like it
should work to me.

If you compile this from the command line yourself, does it work? What
about in VS.NET?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.comwrote in message
news:ur**************@TK2MSFTNGP05.phx.gbl...
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:
PSHcsc /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?)
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.Aut omation\1.0.0.0__31bf3856ad364e35\System.Managemen t.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.

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.

--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
Sep 22 '07 #2
"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.comwrote in message
news:ur**************@TK2MSFTNGP05.phx.gbl...
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:
PSHcsc /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.Aut omation\1.0.0.0__31bf3856ad364e35\System.Managemen t.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.

Sep 22 '07 #3
Marco Shaw wrote:
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;
...
Turns out I was missing the last "using" statement above in my code I
was actually testing.

Sorry!
--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
Sep 23 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Bob | last post: by
2 posts views Thread by Howard Swope | last post: by
2 posts views Thread by ljlevend | last post: by
10 posts views Thread by Paul Cheetham | last post: by
2 posts views Thread by =?Utf-8?B?TWluIFlvbmc=?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.