Why am I getting a nullReferenceException when creating a new DotNetNuke user through C #?

I have the following code in the DotNetNuke module to register a new user:

protected static int RegisterNewDnnAccount(string firstName, string lastName, string email, string password)
    {
        // Create user
        var user = new UserInfo();
        user.FirstName = firstName;
        user.LastName = lastName;
        user.Email = email;
        user.DisplayName = string.Concat(firstName, " ", lastName);
        user.Username = email;
        user.IsSuperUser = false;

        user.Profile.FirstName = firstName;
        user.Profile.LastName = lastName;
        user.Profile.PreferredTimeZone = TimeZoneInfo.Local;
        user.Profile.PreferredLocale = "en-US";
        user.Profile.Telephone = string.Empty;
        user.Profile.Cell = string.Empty;
        user.Profile.PostalCode = string.Empty;
        user.Profile.City = string.Empty;
        user.Profile.Street = string.Empty;
        user.Profile.Region = string.Empty;

        // Set up membership
        var membership = new UserMembership(user);
        membership.Approved = true;
        membership.CreatedDate = DateTime.Now;
        membership.Password = password;
        membership.IsOnLine = false;
        user.Membership = membership;

        // Register the account
        var status = UserController.CreateUser(ref user);
        switch (status)
        {
            case UserCreateStatus.Success:
                return user.UserID;

            case UserCreateStatus.InvalidPassword:
                throw new InvalidOperationException("Failed to create user account: invalid password");

            case UserCreateStatus.InvalidEmail:
                throw new InvalidOperationException("Failed to create user account: Invalid email");

            case UserCreateStatus.DuplicateEmail:
                throw new InvalidOperationException("A user already exists with this email address");

            case UserCreateStatus.UserAlreadyRegistered:
                throw new InvalidOperationException("This user is already registered");

            default:
                throw new InvalidOperationException("user account creation failed for an unknown reason");
        }
    }

When the method is called, the UserController.CreateUser(ref user);DotNetNuke API returns NullReferenceException, with zero information about what is actually zero.

I checked that each of the fields that I set above is not null, so obviously this is what I DO NOT set, which causes this problem. Most of the properties that I configure were from me, trying to stop this error, which I could not do.

Any ideas?


Edit: Here's the stack trace:

at DotNetNuke.Entities.Portals.PortalController.IsMemberOfPortalGroup(Int32 portalId)
    DotNetNuke.Entities.Users.UserController.AutoAssignUsersToRoles(UserInfo user, Int32 portalId)
    DotNetNuke.Entities.Users.UserController.CreateUser(UserInfo& user)
   at PlayerOnDemand.Common.Utils.ClientUserUtils.RegisterNewDnnAccount(String firstName, String lastName, String email, String password) C:\XOS\Projects\DNN\Website\DesktopModules\XOSDigital.PlayerOnDemand\PlayerOnDemand.Common\Utils\ClientUserUtils.cs: 160

+3
2

. , .

+1

DNN, " " , , portalSettings, , , - , , portalSettings, .items.

, , .

, portalSettings , DNN Api - .

0

All Articles