Error when creating new user

Vote:
 

Environment:

  • EPiServer CMS 6 R2
  • EPiServer Relate 2 R2 on top of above

Issue:

  • Trying to add user programmatically but fails and get this error:    "Exception message: Value cannot be null.
    Parameter name: value"

 

This happens when I try to add user or try geta guid.

----------------------------------------------------------------------------------------------------------------------------

IUser newUser = CommunitySystem.CurrentContext.DefaultSecurity.GetUserByUserName(EmailBox.Text.Trim(',')) as IUser;

                if (newUser == null)
                {
                    DatabaseHandler.Instance.RunInTransaction(delegate
                    {
                        newUser = (IUser)CommunitySystem.CurrentContext.DefaultSecurity.NewUser;
                        newUser.UserName = UserNameBox.Text.Trim(',');
                        newUser.EMail = EmailBox.Text.Trim(',');
                        newUser.Password = PasswordBox.Text.Trim(',');
                        newUser.GivenName = FirstNameBox.Text.Trim(',');
                        newUser.SurName = LastNameBox.Text.Trim(',');
                        newUser.Alias = String.Format("{0} {1}", newUser.GivenName, newUser.SurName);
                        newUser.Culture = System.Globalization.CultureInfo.CurrentUICulture;
                  
                        newUser.BirthDate = new DateTime(2008, 3, 9, 16, 5, 7, 123);

                        activationGuid = (Guid)CommunitySystem.CurrentContext.DefaultSecurity.AddUserToActivate(newUser); // Error!******
                        //newUser = (IUser)CommunitySystem.CurrentContext.DefaultSecurity.AddUser(newUser); // Error!*******
                                          
                    });
                }             

#50831
May 13, 2011 10:47
Vote:
 

Can you post the full error (with stacktrace)?

#50844
May 13, 2011 15:27
Vote:
 

Hi,

Here it is:

---------------

System.ArgumentNullException was unhandled by user code
  Message=Value cannot be null.
Parameter name: value
  Source=mscorlib
  ParamName=value
  StackTrace:
       at System.Collections.CollectionBase.OnValidate(Object value)
       at System.Collections.CollectionBase.System.Collections.IList.Add(Object value)
       at EPiServer.Common.Cache.CacheableCollectionBase`2.Add(TItem item)
       at EPiServer.Templates.RelatePlus.CommunityModules.CommunitySecurityModule.DefaultSecurity_CreatedUser(ISecurityHandler sender, ICreateUserEventArgs args)
       at EPiServer.Common.Security.UserCreateEventHandler.Invoke(ISecurityHandler sender, ICreateUserEventArgs args)
       at EPiServer.Common.Security.Data.SecurityFactory.<>c__DisplayClass1.<AddUser>b__0()
       at EPiServer.Common.Data.DatabaseHandler.RunInTransaction(TransactionCode transactionCode)
       at EPiServer.Common.Security.Data.SecurityFactory.AddUser(User user)
       at EPiServer.Common.Security.SecurityHandler.AddUser(IUser user)
       at MyProj.Templates.Units.ForumControls.Register.<>c__DisplayClass2.<AddUser>b__0() in C:\Projects\MyProj\Templates\Units\ForumControls\Register.ascx.cs:line 89
       at EPiServer.Common.Data.DatabaseHandler.RunInTransaction(TransactionCode transactionCode)
       at MyProj.Templates.Units.ForumControls.Register.AddUser() in C:\Projects\MyProj\Templates\Units\ForumControls\Register.ascx.cs:line 74
       at MyProj.Templates.Units.ForumControls.Register.Button1_Click(Object sender, EventArgs e) in C:\Projects\\MyProj\Templates\Units\ForumControls\Register.ascx.cs:line 33
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:

--------------------

Same thing actually happens when I try to create a new user from edit-mode in community tab.

 

 

#50861
May 16, 2011 10:57
Vote:
 

It happens in edit mode too because it occurs in an event handler that always runs when a user is created. Looking at the code makes me suspect that the application setting CommunityMembersGroupName isn't set to the name of an existing group.

#50862
May 16, 2011 11:00
Vote:
 

Hi Magnus and thanks for the quick answer.

I'm quite new to EPiServer, can you explain a bit more regarding the CommunityMembersGroupNam? Is it about some settings in a config file or some configuration I need to set in edit/admin mode?

 

#50864
May 16, 2011 11:18
Vote:
 

There's an application setting class (or whatever they're called) in the Relate templates, EPiServer.Templates.RelatePlus.Properties.Settings in the default install I think. It contains that setting among others. Those application settings files have default values that are compiled, but read from a section in web.config (the node has the same name as the class).

In the default install the setting is "CommunityMembers" and such a group also exists. But if you removed or renamed the group, changed the setting or changed the Settings class and removed the setting you'll have a mismatch here.

You can of course also change the event handler (CommunitySecurityModule.DefaultSecurity_CreatedUser) so it doesn't try to add every user to this group if you don't want that, but remember that the rest of that (giant) class is full of event handlers that set the access rights for that group.

#50865
May 16, 2011 11:23
Vote:
 

I see, thank you very much for the information. I will dig into this a bit more.

#50866
May 16, 2011 11:26
Vote:
 

That solved my problem! the group "CommunityMembers" was missing and everything went fine after I created this group in community admin.

Once again, thanks!

#50867
May 16, 2011 11:44
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.