authenticationnullreferenceexceptionhotmailwinrt-asynclive-connect-sdk

NullReferenceException while calling LoginAsync


In my WinRT app, I want the user to connect to his Hotmail account to access to his contacts. I use the Hotmail API from the Live Connect SDK from Microsoft.

To establish the connection, I use this sample of code of the same documentation.

if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
{
    authClient = new LiveAuthClient();
    LiveLoginResult authResult =
        await authClient.LoginAsync(new string[] { "wl.signin", "wl.basic", "wl.emails" });
    if (authResult.Status == LiveConnectSessionStatus.Connected)
    {
        this.session = authResult.Session;
    }
}

But the code raise a NullReferenceException in the method LoginAsync. Here is the stack trace :

   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 Project.View.TestHotmailConnection.<Button_Click_1>d__0.MoveNext() in TestHotmailConnection.xaml.cs:line 63

I don't think the problem comes from authClient because it isn't null when LoginAsync is called. According to this post, the problem comes from an uninitialized resource dictionary. Does anyone know this problem, and eventually how to resolve it ?

Thanks

EDIT

To use Live Contect in a WinRT app, you need to declare it in the Windows Store Dashboard, maybe it's the solution, I don't have a Windows Store account.


Solution

  • You need to register your app with the store. From VS go to Project -> Store -> Associate App with the Store