2

我也跟着在Azure移動服務網頁上的實時認證教程(http://www.windowsazure.com/en-us/develop/mobile/tutorials/single-sign-on-windows-8-dotnet/(C#)天青 - 現場認證期間空引用異常

,當我運行此行代碼

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

我得到一個「NullReferenceException」無論我做什麼。我嘗試將「wl.basic」更改爲「wl.signin」,但這也不起作用。

我已登錄到我的Microsoft帳戶,我彈出以允許它登錄,該應用程序與我的開發者帳戶相關聯,並且我已將客戶端密鑰和祕密添加到我的天藍色帳戶。 非常感謝大家的幫助!這讓我瘋狂。這是完整的代碼,如果它有幫助。它沒有通過上面所述的線路,我張貼在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() 
+0

你能發佈你得到的全部異常(包括堆棧跟蹤)嗎?這將有助於查明錯誤的位置。 – carlosfigueira

回答