我按照Azure移动服务页面(http://www.windowsazure.com/en-us/develop/mobile/tutorials/single-sign-on-windows-8-dotnet/)
上的实时身份验证教程进行操作当我运行这行代码时
LiveLoginResult result = await liveIDClient.LoginAsync(new[] { "wl.basic" });
无论我做什么,我都会收到“NullReferenceException”。我尝试将“wl.basic”更改为“wl.signin”,但这也无效。
我已登录到我的Microsoft帐户,我收到弹出窗口以允许其登录,该应用程序与我的开发帐户相关联,并且我已将客户端密钥和密码添加到我的Azure帐户。 非常感谢大家的帮助!这让我疯狂。如果它有帮助,这是完整的代码。它没有通过上述行,我也在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 :(得分:3)
我在调用LoginAsync时遇到了同样的问题 - “对象引用未设置为对象的实例”。 确保您已在Live Connect设置中输入重定向URL - 请参阅所附链接的步骤4 - https://www.windowsazure.com/en-us/develop/mobile/how-to-guides/register-for-microsoft-authentication/
谢谢!