我按照 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 帐户,收到弹出窗口以允许其登录,该应用程序已关联到我的开发帐户,并且我已将客户端 key 和 secret 添加到我的 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)
{}
异常(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()
最佳答案
调用 LoginAsync 时,我遇到了同样的问题 -“对象引用未设置为对象的实例”。 确保您已在 Live Connect 设置中输入重定向 URL - 请参阅所附链接的步骤 4 - https://www.windowsazure.com/en-us/develop/mobile/how-to-guides/register-for-microsoft-authentication/
谢谢!
关于c# - (C#) Azure - 实时身份验证期间出现空引用异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20487215/