Try our conversational search powered by Generative AI!

Error when creating new user



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


  • 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)
                        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!*******

May 13, 2011 10:47

Can you post the full error (with stacktrace)?

May 13, 2011 15:27


Here it is:


System.ArgumentNullException was unhandled by user code
  Message=Value cannot be null.
Parameter name: value
       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)


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



May 16, 2011 10:57

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.

May 16, 2011 11:00

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?


May 16, 2011 11:18

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.

May 16, 2011 11:23

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

May 16, 2011 11:26

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

Once again, thanks!

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.