3

Now that PowerShell is open sourced and available on Linux, any one knows how to add .Net assemblies under linux? if at all possible?

I have installed PS on Ubuntu 16.04 as in here and installed Mono as in here.

After running PS on terminal, this line surprisingly works just fine:

add-type -assembly "/usr/lib/mono/4.5-api/System.Web.Extensions.dll"

No errors etc...

Yet when I try to:

$js = New-Object "System.Web.Script.Serialization.JavaScriptSerializer"

I am getting this error:

new-object : Cannot find type [System.Web.Script.Serialization.JavaScriptSerializer]: verify that the 
assembly containing this type is loaded.
At line:1 char:10
+ $ps_js = new-object "System.Web.Script.Serialization.JavaScriptSerial ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

Any hints on that one? Is it a bug maybe as powershell on linux is still "alpha"?

BTW - On windows all is working just fine...

2
  • Miguel de Icaza confirmed it does not work with Mono yet, so you can only run it with .NET Core right now.
    – Lex Li
    Commented Aug 21, 2016 at 1:27
  • Any reference to that confirmation?
    – It-Z
    Commented Aug 21, 2016 at 7:41

1 Answer 1

4

PowerShell on Linux is based on CoreCLR while mono is a clone of the CLR / full framework. The assembly you are using is a full framework one and cannot load in CoreCLR since it is based on mscorlib and not System.Runtime.

In a year there will be a workaround (maybe) with the upcoming .NET Standard 2.0.

Json serialization should be native in PowerShell, if not use newtonsoft.json.

Not the answer you're looking for? Browse other questions tagged or ask your own question.