IIS has some problems with compiling C# on the fly in PowerShell. You’ll notice similar issues with New-WebServiceProxy.
You can work around this by using Add-Type outside of Universal and use the -OutputAssembly parameter. Then in your script, load the assembly with Add-Type or System.Reflection.Assembly.LoadFrom.