调用LoginAsync时出现NullReferenceException

时间:2013-03-27 10:46:08

标签: login nullreferenceexception hotmail winrt-async live-connect-sdk

在我的WinRT应用中,我希望用户连接到他的Hotmail帐户以访问他的联系人。我使用了Microsoft的Hotmail API中的Live Connect SDK

要建立连接,我使用相同文档的sample代码。

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;
    }
}

但是代码在方法LoginAsync中引发了NullReferenceException。这是堆栈跟踪:

   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

我不认为问题来自authClient,因为在调用LoginAsync时它不会为null。根据这个post,问题来自未初始化的资源字典。有谁知道这个问题,最终如何解决它?

由于

修改

要在WinRT应用中使用Live Contect,您需要在Windows Store Dashboard中声明它,也许它是解决方案,我没有Windows Store帐户。

2 个答案:

答案 0 :(得分:3)

您需要在商店注册您的应用。从VS转到Project - &gt;商店 - &gt;将应用程序与商店关联

答案 1 :(得分:0)

我对5.6.2.0也有同样的问题。

要解决此问题(作为解决方法),我将Microsoft.Live.pri和Microsoft.Live \ SDKManifest.xml放在Microsoft.Live.dll旁边(来自https://github.com/liveservices/LiveSDK-for-Windows)。否则它无法获得错误描述(对于任何错误情况,例如没有互联网等)和崩溃。

我为此问题添加了一个代码。它看起来像配置问题