0

I'm trying to use this code in Powershell:

Add-Type -AssemblyName "System.Collections.Generic"

However I get this error:

Add-Type : Cannot add type. One or more required assemblies are missing.

I've looked in C:\windows\assembly\GAC_MSIL and can see that there is no folder named System.Collections.Generic.

Do I need to download this library, if so where?

David Klempfner
  • 8,700
  • 20
  • 73
  • 153

3 Answers3

1

There is no System.Collections.Generic assembly. That is a namespace. A large portion of the types in that namespace are in the core library assembly, mscorlib.dll which is already available in Powershell since Powershell is .Net.

Go to MSDN for the namespace, find the type you are trying to use, and you can see the assembly it is in, and remember that there is not necessarily a one to one relationship between assemblies and namespaces.

Using generic types is a bit involved in Powershell and can depend on using reflection, or formatting complex type names.

See this stackoverflow question for some more details.

Community
  • 1
  • 1
Joseph Alcorn
  • 2,322
  • 17
  • 23
0

Never mind, not sure why that doesn't work, but turns out I don't need it anyway.

I had this code which for some reason wasn't working intially because it couldn't find [Collections.Generic.List[String]], but now it seems to work:

[string[]] $csvUserInfo = @([IO.File]::ReadAllLines($script:EmailListCsvFile))
[Collections.Generic.List[String]]$x = $csvUserInfo
David Klempfner
  • 8,700
  • 20
  • 73
  • 153
0

I would answer by another question, Why do you need this assembly ?

Can you try to replace your code by :

$x = [IO.File]::ReadAllLines($script:EmailListCsvFile)

In PowerShell it should work.

JPBlanc
  • 70,406
  • 17
  • 130
  • 175