在我的 WinRT 应用程序中,我希望用户连接到他的 Hotmail 帐户以访问他的联系人。我使用Microsoft Live Connect SDK中的Hotmail API 。
为了建立连接,我使用了相同文档的代码示例。
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 时它不为空。根据这篇文章,问题来自未初始化的资源字典。有谁知道这个问题,最终如何解决?
谢谢
编辑
要在 WinRT 应用程序中使用 Live Contect,您需要在Windows Store Dashboard中声明它,也许这是解决方案,我没有 Windows Store 帐户。