Microsoft.Lync.Model.LyncClient.BeginSignIn 异常:System.Invali



我正在使用 Lync 客户端登录帐户:

_LyncClient = LyncClient.GetClient(true);
if (_LyncClient == null)
{
    throw new Exception("Unable to obtain client interface");
}
_LyncClient.SignInDelayed += _LyncClient_SignInDelayed;
_LyncClient.StateChanged += _LyncClient_StateChanged;
_LyncClient.CredentialRequested += _LyncClient_CredentialRequested;
......
try
{     
    if (_LyncClient.State == ClientState.SignedIn)
    {
        _LyncClient.BeginSignOut(
            ar =>
            {
                //Set a class field flag so that the application 
                //shuts down the Lync platform when the application closes
                _LyncClient.EndInitialize(ar);
            },
            null);
    }
    if (_LyncClient.State == ClientState.Uninitialized)
    {
        _LyncClient.BeginInitialize(
            ar =>
            {
                //Set a class field flag so that the application 
                //shuts down the Lync platform when the application closes
                _LyncClient.EndInitialize(ar);
                //_LyncClient.StateChanged += _LyncClient_StateChanged;
            },
            null);
    }
    if (_LyncClient.State == ClientState.SignedOut)
    {
        if (_callback != null)
            _callback.OnSignInStart();
        _LyncClient.BeginSignIn(
            this.email,
            upnOrDomainUserName,
            password,
            ar =>
            {
                _LyncClient.EndSignIn(ar);
                if (_callback != null)
                {
                    _callback.OnSignInSuccess();
                }
            },
            null);
    }
}
catch (NotStartedByUserException h)
{
    throw new Exception("Lync is not running: " + h);
}
catch (Exception ex)
{
    throw new Exception("General Exception: " + ex);
}

但是,此代码会生成异常:

    General Exception: System.InvalidOperationException: Operation is not valid due to the current state of the object. at Microsoft.Lync.Model.LyncClient.BeginSignIn(String userUri, String domainAndUsername, String password, AsyncCallback communicatorClientCallback, Object state)

什么会导致这种情况?我无法从搜索中找到任何信息。该代码作为 Windows 服务运行。

谢谢

我也

做了一个快速的谷歌搜索,你的问题可能是环境问题。在此处查看相同的错误。

相关内容

最新更新