Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 05, 2010 @ 21:07
    Ferdy Hoefakker
    0

    making a member gives an "object reference not set to an instance" error

    I am trying to make a registration form so people can register on my website. However, everytime I actually try to save the new member, the application blows up in my face.

    if (Membership.GetUserNameByEmail(txtEmail.Text) == null)
    {
    //create a member
    MembershipUser newUser = Membership.CreateUser(txtUserName.Text.ToString(), txtPassWord.Text.ToString(), txtEmail.Text.ToString());
    Roles.AddUserToRole(txtUserName.Text, "websiteMember");
    }

    That is the code I am trying to use. I want to check if there already is a member using the given email address and if there isn't, I want to create a new member using the data supplied by the user. The "== null" part is probably wrong, but I tried a dozen of different things already and nothing works.

    Stack trace error:

    [NullReferenceException: Object reference not set to an instance of an object.]
    umbraco.cms.businesslogic.Content.CreateContent(ContentType ct) +188
    umbraco.cms.businesslogic.member.Member.MakeNew(String Name, String Email, MemberType mbt, User u) +601
    umbraco.providers.members.UmbracoMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) +197
    System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) +207
    System.Web.Security.Membership.CreateUser(String username, String password, String email) +30
    memberControls.memberControls.memberSignUp.btnSubmit_Click(Object sender, EventArgs e) +259
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

    I am using Umbraco 4.5.1 and after some searching, I still have been unable to find an answer, maybe I missed it, but if I could be pointed in the right direction that would be great.

    -Ferdy

  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 06, 2010 @ 16:55
    Ferdy Hoefakker
    0

    Would still like to get an answer to this ;)

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Aug 06, 2010 @ 17:18
    Michael Latouche
    1

    Hi Ferdy,

    If I saw correctly in the error message, you are using the umbraco membership manager, so just to make sure: do you have a "MemberType" defined in umbraco member manager, and did you specify the name of that member type in the declaration of your membership provider in the web.config file?

    If you look at the second line of your error, it states:

    umbraco.cms.businesslogic.member.Member.MakeNew(String Name, String Email, MemberType mbt, User u)

    The name of the member type to use is normally defined within you membership provider definition and is passed automatically when creating new members. So my guess is that it is either missing in the web.config file, or it is defined there but it does not actually exist within umbraco.

    Hope it helps!

    Cheers,

    Michael

  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 06, 2010 @ 17:29
    Ferdy Hoefakker
    0

    Thanks Micheal, that totally did the trick. I did this before on 4.0.3 or something, and back then I just followed the example on http://www.nibble.be/?p=20. When I tried this time however, those functions said deprecated so I figured it'd be better to just try the new way. Never knew I had to set something in the web.config to make that work :)

    -Ferdy

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Aug 06, 2010 @ 17:32
    Michael Latouche
    0

    Great !

    Always nice to end the week on a positive note, isn't it :-)

    Cheers,

    Michael.

  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 06, 2010 @ 17:34
    Ferdy Hoefakker
    0

    Sure is! :)

    Thanks again.

    -Ferdy

  • Vijay 30 posts 47 karma points
    Aug 07, 2010 @ 18:32
    Vijay
    0

    Guys,

      I am running into the same problem with 4.5.1, except that it creates the member without any errors but none of the additional properties on the Member type get saved.  For example I created 2 properties "address" and "zip" on the member type. In my code i followed the instructions on  http://www.nibble.be/?p=20 to save those properties:

                  newMember.getProperty(“address”).Value = "abc drive" //set value of property with alias ‘address’

                    newMember.getProperty(“zip”).Value = "44444" //set value of property with alias ‘zip’

     It creates my new user but does not save these properties.  Please help

  • Dimitris Papadimitriou 14 posts 34 karma points
    Jul 28, 2011 @ 00:07
    Dimitris Papadimitriou
    0

    Hi,

    I'm getting the Object Reference not set exception when I call Membership.CreateUser as well.

    Michael I guess that I don't understand completely the solution you suggest, since I cannot make this work. What I understand is that I should create a User Type using the Umbraco back office UI and I should put the alias of that user type in the defaultMemberTypeAlias attribute of the UmbracoMembershipProvider in the web.config. Right? And this will be the default user type when a new user is created by the Membership.CreateUser method.

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jul 28, 2011 @ 15:01
    Michael Latouche
    0

    Hi Dimitris,

    That is indeed the first thing to do. Normally the error should disappear.

    And otherwize we'll look further ;-)

    Cheers,

    Michael

  • Dimitris Papadimitriou 14 posts 34 karma points
    Aug 05, 2011 @ 11:22
    Dimitris Papadimitriou
    0

    Ok I don't have the exception any more. Not sure what I did. Probably I just fixed my Member Groups and Types. It would be nice if you could throw a better exception in this case. :)

  • Lincoln Vu 8 posts 29 karma points
    Jul 30, 2012 @ 20:59
    Lincoln Vu
    0

    Just to elaborate Michael Latouch's instructions: open web.config, modify value of "defaultMemberTypeAlias=" to the alias that you see under Umbraco web admin panel > Members > MemberTypes > "Values-that-you-set"

    (by default it's "Another Type", I changed it in my web admin panel without knowing it's referenced in web.config -> registration break)

Please Sign in or register to post replies

Write your reply to:

Draft