我的 DotNetNuke 模块中有以下代码来注册新用户:
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");
}
}
当该UserController.CreateUser(ref user);
方法被调用时,DotNetNuke 的 API 会抛出一个NullReferenceException
,当然关于什么是 null 的信息为零。
我已经验证了我在上面设置的每个字段都不为空,所以很明显这是我没有设置的东西导致了这个问题。我设置的大多数属性都是我试图让这个错误停止,但我没有做到这一点。
有任何想法吗?
编辑:这是堆栈跟踪:
在C
DotNetNuke.Entities.Portals.PortalController.IsMemberOfPortalGroup(Int32 portalId)
: \XOS\Projects\DNN\Website\DesktopModules\DotNetNuke.Entities.Users.UserController.AutoAssignUsersToRoles(UserInfo user, Int32 portalId)
XOSDigital.PlayerOnDemand \DotNetNuke.Entities.Users.UserController.CreateUser(UserInfo& user)
PlayerOnDemand.CommonPlayerOnDemand.Common.Utils.ClientUserUtils.RegisterNewDnnAccount(String firstName, String lastName, String email, String password)
\Utils\ClientUserUtils.cs:line 160