そう!これは私には非常に奇妙に思えるので、頭が爆発しました。デバッグ モードを使用すると、Claimsresponse がメソッドに取り込まれ、データが入力されるのを確認できます。Email プロパティも同様です。しかし、単純な文字列 myStr = response.Email; を試すと、NullException エラーがスローされます...
私はそれを理解していません..
コード: (設定メールが失敗します!)
public static bool LoginUserUsingOpenID(BaseDBContext db, ClaimsResponse r)
{
string email = r.Email;
bool doesntExist = !UserHelper.DoesUserExist(db, r.Email);
User u = null;
if (doesntExist)
{
u.Email = email;
u.Username = "User" + new Random().Next(100000);
u.Password = CreateRandomPassword(7);
u.prepareForCreationFromThirdParty();
}
else
{
u = db.Users.Where(x => x.Email == r.Email).FirstOrDefault();
}
SetUserAsAuthenticated(u);
AddAutomaticLoginKeyForUser(db, u); //Need to get this to the users frontend somehow..
return true;
}
スタック トレースは次のとおりです。
System.NullReferenceException: Object reference not set to an instance of an object.
at MusingMonkey.Helpers.SecurityHelper.LoginUserUsingOpenID(BaseDBContext db, ClaimsResponse r) in C:\Users\William-Business\Desktop\TWB\TWB Central\Projects\MusingMonkey\MusingMonkey\Helpers\SecurityHelper.cs:line 170
at MusingMonkey.Controllers.UsersController.HandleOpenIDResponse() in C:\Users\William-Business\Desktop\TWB\TWB Central\Projects\MusingMonkey\MusingMonkey\Controllers\UsersController.cs:line 78
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)