(C#)天青 - 现场验证期间空引用异常 [英] (C#) Azure - Null Reference Exception during Live Authentication
问题描述
我也跟着在Azure移动服务网页上实时认证教程(的http://www.windowsazure.com/en-us/develop/mobile/tutorials/single-sign-on-windows-8-dotnet/)
,当我跑这条线code的
LiveLoginResult结果=等待liveIDClient.LoginAsync(新[] {wl.basic});
我得到一个的NullReferenceException不管我做什么。我试图改变wl.basic到wl.signin,而且没有任何工作。
我签署了我的Microsoft帐户,我得到了弹出,使其能够登录,应用程序关联到我的dev的帐户,我已经添加客户端密钥和密码到我的蔚蓝帐户。
由于一吨的帮助大家!它的驾驶我疯了。下面是完整的code。如果它帮助。它没有获得通过行上述,我在MSDN上公布为好,只是想将计算器更有帮助。
私人LiveConnectSession会议;
私人异步System.Threading.Tasks.Task进行身份验证()
{
LiveAuthClient liveIDClient =新LiveAuthClient(https://mobileserviceexample.azure-mobile.net/); 而(会话== NULL)
{ // TODO:增加了对多个Microsoft帐户进行测试。只适用于非关联帐户
如果(liveIDClient.CanLogout)
{liveIDClient.Logout(); } LiveLoginResult结果=等待liveIDClient.LoginAsync(新[] {wl.basic});
如果(result.Status == LiveConnectSessionStatus.Connected)
{}
例外:
System.NullReferenceException是由用户code未处理
的HResult = -2147467261
消息=对象引用未设置到对象的实例。
来源= Microsoft.Live
堆栈跟踪:
在Microsoft.Live.ResourceHelper.GetString(字符串名称)
在Microsoft.Live.TailoredAuthClient< AuthenticateAsync> d__0.MoveNext()
---从previous位置堆栈跟踪,其中引发异常的结尾---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
在Microsoft.Live.LiveAuthClient< ExecuteAuthTaskAsync> d__4.MoveNext()
---从previous位置堆栈跟踪,其中引发异常的结尾---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
在CommunistTutsApp.HomePage<身份验证> d__0.MoveNext()
---从previous位置堆栈跟踪,其中引发异常的结尾---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.GetResult()
在CommunistTutsApp.HomePage<&的OnNavigatedTo GT; d__f.MoveNext()
我有同样发出─调用LoginAsync时对象引用不设置到对象的实例。
请确保您输入的重定向URL中的实时连接设置 - 见附件链路的步骤4
<一href=\"https://www.windowsazure.com/en-us/develop/mobile/how-to-guides/register-for-microsoft-authentication/\" rel=\"nofollow\">https://www.windowsazure.com/en-us/develop/mobile/how-to-guides/register-for-microsoft-authentication/
感谢您!
I followed the Live Authentication tutorial on the Azure Mobile Services page (http://www.windowsazure.com/en-us/develop/mobile/tutorials/single-sign-on-windows-8-dotnet/)
and when I run this line of code
LiveLoginResult result = await liveIDClient.LoginAsync(new[] { "wl.basic" });
I get a "NullReferenceException" no matter what I do. I tried changing "wl.basic" to "wl.signin" and that didn't work either.
I am signed into my Microsoft Account, I get the pop-up to allow it to login, the app is associated to my dev account, and I have added the client key and secret to my azure account. Thanks a ton for the help everyone! It's driving me crazy. Here's the full code if it helps. It doesn't get passed the line stated above and I posted on MSDN as well, just thought StackOverflow would be more helpful.
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()
I had the same issue- "Object Reference not set to the instance of an object" when calling LoginAsync. Make sure you have entered the Redirect URL in the Live Connect setup- see Step 4 of the attached link- https://www.windowsazure.com/en-us/develop/mobile/how-to-guides/register-for-microsoft-authentication/
Thank you!
这篇关于(C#)天青 - 现场验证期间空引用异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!