(C#) Azure - Null Reference Exception during Live Authentication

≡放荡痞女 提交于 2020-01-04 13:47:04

问题


I followed the Live Authentication tutorial on the Azure Mobile Services page (http://www.windowsazure.com/en-us/develop/mobile/tutorials/single-sign-on-windows-8-dotnet/)

and when I run this line of code

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

I get a "NullReferenceException" no matter what I do. I tried changing "wl.basic" to "wl.signin" and that didn't work either.

I am signed into my Microsoft Account, I get the pop-up to allow it to login, the app is associated to my dev account, and I have added the client key and secret to my azure account. Thanks a ton for the help everyone! It's driving me crazy. Here's the full code if it helps. It doesn't get passed the line stated above and I posted on MSDN as well, just thought StackOverflow would be more helpful.

 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)
            {}

Exception:

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()

回答1:


I had the same issue- "Object Reference not set to the instance of an object" when calling LoginAsync. Make sure you have entered the Redirect URL in the Live Connect setup- see Step 4 of the attached link- https://www.windowsazure.com/en-us/develop/mobile/how-to-guides/register-for-microsoft-authentication/

Thank you!



来源:https://stackoverflow.com/questions/20487215/c-azure-null-reference-exception-during-live-authentication

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