I’m using PowerShell Studio and getting this anoying error. I started the code in ISE and it was working fine but ported to PSS started getting this error. It would make sense to post on PSS forums but they are not working. Hoping someone can help.
This is one of the errors:
ERROR: At Line: 166 char: 29
ERROR: + [System.Uri]$configUrl = [System.Web.HttpUtility]::UrlDecode( …
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~
ERROR: Unable to find type [System.Web.HttpUtility].
ERROR:
This code goes something like this:
class MyClass: IDisposable
{
# props
MyClass()
{
[System.Uri]$configUri = Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Company' -Name 'ConfigUri'
$this.init($configUri)
}
# another constructor
# dispose
hidden [void]init([System.Uri]$Uri)
{
Add-Type -AssemblyName System.Web
Add-Type @"
#<inline C# code that also is not working>
"@
[System.Uri]$configUrl = [System.Web.HttpUtility]::UrlDecode($Uri)
# some more code goes here
}
# a few other methods
}
function Main
{
$wp = [MyClass]::New()
}
I tried to use the Add-Type in the class method as is showing, the class constructors, the Main function, the top of the file and added teh system.web to the default editor assemblies.
This is a Windows 64bit Sapien PS v5 host silent project in STA mode and doesn’t require elevation.
Thanks Olaf.
The code is actually how I have it on the sample code and it’s just before the command. Only the inline Add-Type is in the middle but I tried to remove it and still getting the error.
The editor recognizes, intellisense works fine and running in console works too.
How about removing everything else what is not working and just have the two pieces you need for this particular part of the functionality to figure out what the issue is?
Yeah, they say it’s fixed on PS7 but I’ve been procrastinating using PS7. there’a lot of interesting features, particularly parallelism but I can’t take time learning new PS or adjusting my scripts and for my line of work, it doesn’t make much sense as it’s not even generally deployed on devices.
I found that using [System.Uri]$configUrl = [System.Net.WebUtility]::UrlDecode($Uri) works fine so I’m using this instead. I don’t know why but won’t spend any more time around this!
As per my inline C# class, I changed it so I can instantiate and call the method instead and it works.