So I ran into this exact problem: http://www.vistax64.com/powershell/273120-bug-when-using-namespace-parameter-new-webserviceproxy.html
The gist of the issue is that whe
Are you running your code in some editor? I had similar problem when running script from PowerGUI editor, but it is working fine for me when I run it from console. Try close all your powershell related stuff and open it again
Actually you're seeing something a notch more subtle. With -Namespace, you cannot execute an argument of the type in the namespace twice
I suspect you're creating New-WebServiceProxy a lot, like, in the process block of a function, or inside of a command that's called repeatedly. Every time you call it, it tries to regenerate, and, with -Namespace, this leaves little collisions with associated types in the AppDomain. There end up being several of them, and you get this error.
There are two ways around this:
This is far easier to show than tell.
I had this problem with a module I have for Office365 / Exchange Web Services, and, beneath the covers, it has something like:
$createItemType =
New-Object "$script:ExchangeWebServiceNamespace.CreateItemType"
-Property @{
MessageDisposition = $messageDisposition
MessageDispositionSpecified = $true
Items =
New-Object "$script:ExchangeWebServiceNamespace.NonEmptyArrayOfAllItemsType"
}
This is obviously a little cryptic, but, well, so is Exchange Web Services. And so are many web services that are built directly from complex object models.
Unfortunately, that is the vast majority of web services that New-WebServiceProxy works with.
Bear in mind, it's still good practice to cache the web service object you create in your module (using $script:variablename
like above), but this weird trick to reference web service parts by the proxy object has saved me more times than I'd like.
Hope this Helps