This is my code to add user directly. The membership section works, but AddUser returns this error :
An exception occurred creating the user. The type initializer for 'DSC' threw an exception. System.NullReferenceException: Object reference not set to an instance of an object. at DotShoppingCart.Commercial.Base.Constant.DSC..cctor()
MembershipCreateStatus status;
try
{
MembershipUser m = Membership.CreateUser(nU.UserName, nU.PassWord , nU.Email , "The greatest band ever?", "none", true, out status);
if (m == null)
{
errorMsg += GetErrorMessage(status) + Environment.NewLine;
Error.Msg = errorMsg;
return (0);
}
else
{
errorMsg += "User " + nU.UserName + " added " + Environment.NewLine;
DSC.User.AddUser(nU.UserName, nU.NewsLetter , CoreHelper.GetReferralId(), nU.FirstName,
nU.LastName, nU.CompanyName, nU.Address, nU.Address2, nU.City, nU.State,
nU.Zipcode, nU.CountryId , nU.Phone , nU.PhoneExt , nU.Created, false );
string roleName = HttpContext.Current.Session["registerRole"] as string;
if ((!string.IsNullOrEmpty(roleName)) && (roleName != Constant.Security.AdminRole))
{
Roles.AddUserToRole(nU.UserName, roleName);
}
return (1);
}
}
catch (Exception e)
{
errorMsg += "An exception occurred creating the user." + Environment.NewLine + "\n\r" + e.Message + "\n\r" + e.InnerException ;
Error.Msg = errorMsg;
return (0);
}
}