views:

27

answers:

1

Hi,

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!

+1  A: 

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.

o.k.w
This code works for dummy test accounts I created - they seem to be getting here, and updated according to the following code.I will try debugging this locally - one problem is that my remote and local database is different, so it might take me a bit to get back to you on debugging the specific accounts causing the trouble.Thanks so much for the quick reply.
stringo0
@stringo0: Good luck in your debugging!
o.k.w
stringo0
It's the linq select statement, not sure why - starting another question for it because it's a different problem.
stringo0