Microsoft.Lync.Model.LyncClient.BeginSignIn异常:System.InvalidOperationException:由于对象的当前状态,操作无效

时间:2018-03-21 20:36:47

标签: c# sdk skype lync skypedeveloper

我正在使用Lync Client登录帐户:

_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服务运行。

由于

1 个答案:

答案 0 :(得分:0)

我也快速进行了Google搜索,您的问题可能是一个环境问题。请参阅相同的错误here