使用“3”参数调用“BeginSendMessage”的异常:“值不在预期范围内。”

时间:2013-10-08 17:58:20

标签: powershell sdk lync

我正在尝试为单一联系人IM(通过Microsoft Lync)执行脚本,并且已经成功地将脚本一直运行到最后一行:

$null = $m.BeginSendMessage($d, $null, $d)

注意:

$d = New-Object "System.Collections.Generic.Dictionary [Microsoft.Lync.Model.Conversation.InstantMessageContentType, String]"

$d.Add($PlainText, "This is a test.")

以下是Psh在执行此语法时抛出的异常。它似乎在启动$ null变量时失败。

Exception calling "BeginSendMessage" with "3" argument(s): "Value does not fall within the expected range."
At C:\ScriptsPS\IM_SingleContact.ps1:75 char:1
+ $null = $m.BeginSendMessage($d, $null, $d)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 个答案:

答案 0 :(得分:0)

第二个参数必须是回调方法。 Using AsyncCallback in Powershell有一个简单的例子:

$myCallback = [AsyncCallback]{
  param( $asyncResult)
  # callback code
  if ($asyncResult.isCompleted) {
    Write-Host "Message Sent"
  }
}
[void]$m.BeginSendMessage($d, $myCallback, $d)
相关问题