为什么我不能忽略使用PowerShell的调用的返回值?

Gur*_*ruJ 5 powershell

当我在Powershell中从外部类型调用它时:

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

我可以看到函数调用返回一个int.我收到以下错误消息:

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.
Run Code Online (Sandbox Code Playgroud)

我不需要任何东西的int值,但我似乎无法指示Powershell忽略它.例如,这些仍然返回相同的错误:

[void]$queryProcessor.Process(query)
$queryProcessor.Process(query) | Out-Null
Run Code Online (Sandbox Code Playgroud)

我还能尝试什么?

Jas*_*irk 7

您正在使用PowerShell中的错误.

请尝试以下解决方法:

$queryProcessor.Process.Invoke(query)
Run Code Online (Sandbox Code Playgroud)

  • 并解释 - $ queryProcessor.Process返回一个PSMethod.实现PSMethod.Invoke(...)的代码路径没有错误. (4认同)