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.
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.
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:
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.
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 :)
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
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.
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. :)
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)
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.
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:
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
Would still like to get an answer to this ;)
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
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
Great !
Always nice to end the week on a positive note, isn't it :-)
Cheers,
Michael.
Sure is! :)
Thanks again.
-Ferdy
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
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.
Hi Dimitris,
That is indeed the first thing to do. Normally the error should disappear.
And otherwize we'll look further ;-)
Cheers,
Michael
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. :)
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)
is working on a reply...