Weird error in ASP.net UserCreate Wizard
I'm having a weird error. During user creation, if a username already exists in the system, I do a few checks on it and allow the user to sign up again if the existing account is not activated yet. I'm getting an error 开发者_运维问答that says:
[NullReferenceException: Object reference not set to an instance of an object.]
LAUNCHOnline.en.ca.CreateUser.wCreateUser_Error(Object sender, CreateUserErrorEventArgs e) in C:\Projects\LAUNCH\LAUNCH-Online\LAUNCHOnline\en\ca\CreateUser.aspx.cs:194
My Code: (var vUser is the line causing the error)
protected void wCreateUser_Error(object sender, CreateUserErrorEventArgs e)
{
// TODO: more verbose error messages.
if (e.CreateUserError == MembershipCreateStatus.DuplicateEmail)
{
// WORK IN PROGRESS
// If the user is not activated yet, update the existing user info with the new info
// as it might be a feedback user. Else, give an error.
// Get the user from the database.
var vUser = (from u in this.dcLAUNCHOnline.aspnet_Users
where u.UserName.Equals(this.wCreateUser.UserName)
select u).Single();
Note: The user's username is just their email. I manually checked, and people who are getting this error do have an account in the database already, but still get this error. The case of the username didn't cause the problem, as I tried different cases with temp accounts and it worked fine.
Any Help appreciated - thanks!
If the NullReferenceException exception is thrown from this line:
var vUser = (from u in this.dcLAUNCHOnline.aspnet_Users
where u.UserName.Equals(this.wCreateUser.UserName)
select u).Single();
The problem has to be one of the following instances (or the lack of it):
dcLAUNCHOnline.aspnet_Users
this.wCreateUser
OR no result from
from u in this.dcLAUNCHOnline.aspnet_Users where u.UserName.Equals(this.wCreateUser.UserName)
I suggest you debug through to find out which one or more is/are null
.
精彩评论