Exception calling “BeginSendMessage” with “3” argument(s): “Value does not fall within the expected range.”

懵懂的女人 提交于 2019-12-12 03:52:37

问题


I am attempting to execute a script for single contact IM (via Microsoft Lync), and have successfully ran the script all the way down to the last line:

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

Note:

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

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

Below is the exception Psh is throwing upon execution of this syntax. It appears to fail at initiation of the $null variable.

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:


The second argument has to be a callback method. Using AsyncCallback in Powershell has a simple example:

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


来源:https://stackoverflow.com/questions/19254906/exception-calling-beginsendmessage-with-3-arguments-value-does-not-fall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!