(C#)Azure-实时身份验证期间出现Null引用异常



我在Azure移动服务页面上学习了实时身份验证教程(http://www.windowsazure.com/en-us/develop/mobile/tutorials/single-sign-on-windows-8-dotnet/)

当我运行这行代码时

LiveLoginResult result = await liveIDClient.LoginAsync(new[] { "wl.basic" });

无论我做什么,我都会得到一个"NullReferenceException"。我试着把"wl.basic"改为"wl.signin",但也没用。

我已经登录到我的Microsoft帐户,我得到了允许它登录的弹出窗口,该应用程序与我的开发帐户相关联,我已经将客户端密钥和机密添加到我的azure帐户中。非常感谢大家的帮助!它把我逼疯了。如果有帮助的话,下面是完整的代码。它没有通过上面所说的那一行,我也在MSDN上发帖,只是觉得StackOverflow会更有帮助。

 private LiveConnectSession session;

    private async System.Threading.Tasks.Task Authenticate()
    { 
     LiveAuthClient liveIDClient = new LiveAuthClient("https://mobileserviceexample.azure-mobile.net/");
        while (session == null)
        {
            // TODO: Added for testing of multiple microsoft accounts. Only works on non-connected accounts
            if (liveIDClient.CanLogout)
            { liveIDClient.Logout(); }
            LiveLoginResult result = await liveIDClient.LoginAsync(new[] { "wl.basic" });
            if (result.Status == LiveConnectSessionStatus.Connected)
            {}

例外:

System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Microsoft.Live
StackTrace:
   at Microsoft.Live.ResourceHelper.GetString(String name)
   at Microsoft.Live.TailoredAuthClient.<AuthenticateAsync>d__0.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Live.LiveAuthClient.<ExecuteAuthTaskAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task     task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at CommunistTutsApp.HomePage.<Authenticate>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task     task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at CommunistTutsApp.HomePage.<OnNavigatedTo>d__f.MoveNext()

我在调用LoginAsync时遇到了同样的问题——"对象引用未设置为对象的实例"。确保您已在Live Connect设置中输入重定向URL-请参阅附加链接的步骤4-https://www.windowsazure.com/en-us/develop/mobile/how-to-guides/register-for-microsoft-authentication/

谢谢!

最新更新