Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I ignore a return value of a call using PowerShell?

Tags:

powershell

When I call this from an external type in Powershell:

Add-Type -Path "$sdk_path\bin\DataProvider.dll"
$queryProcessor = New-Object -Type QuestionAnswering.QueryProcessor($linguisticDB, $index)
$queryProcessor.Process(query)

I can see that the function call returns an int. I get the following error message:

The result type 'System.Int32' of the dynamic binding produced by the object with type 
'System.Management.Automation.PSObject' for the binder 'PSInvokeMember: Process ver:0 
args:1 constraints:<args: >' 
is not compatible with the result type 'System.Object' expected by the call site.

I don't need the int value for anything, but I can't seem to instruct Powershell to ignore it. For example, these still return the same error:

[void]$queryProcessor.Process(query)
$queryProcessor.Process(query) | Out-Null

What else can I try?

like image 619
GuruJ Avatar asked Mar 03 '14 22:03

GuruJ


1 Answers

You are hitting a bug in PowerShell.

Try the following as a workaround:

$queryProcessor.Process.Invoke(query)
like image 117
Jason Shirk Avatar answered Sep 28 '22 10:09

Jason Shirk