0

I can't work out why:

Exception calling "GetSites" with "1" argument(s): "Cannot convert the
"WS.WSErrorObject" value of type "WS.WSErrorObject" to type "WS.WSErrorObject"."
At ...
+ WS.WSSiteEntity[] $sites = $webServiceProxy.GetSites([ref] $wsError)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PSInvalidCastException

The code is quite simple:

$webServiceProxy = New-WebServiceProxy -Uri $elevateUri -Credential $credential -Namespace WS

$wsError = New-Object -TypeName WS.WSErrorObject

WS.WSSiteEntity[] $sites = $webServiceProxy.GetSites([ref] $wsError)

It's similar to PowerShell 5 and classes - Cannot convert the "X" value of type "X" to type "X", so I think it has to do with there being multiple copies of the same type but I still can't work it out.

I have tried with full autogenerated typenames (i.e. not using a namespace for the Web Service proxy) and the result is the same.

I've tried to use weak typing but don't know how to declare wsError for the reference without constructing a new object and giving it a type.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Ashley Aitken
  • 2,419
  • 2
  • 20
  • 24

0 Answers0