User and SuperUser Manager fail with null reference exception
Problem
When clicking the <Users> icon in the Admin Panel, or clicking the <SuperUser Accounts> in the <Host> menu I am getting a Null Reference Exception failure.
Analysis
The exception occurs in the ConvertMembershipToUserInfo function of of the UserAccounts class in the DotNetNuke.Modules.Admin.Users namespace that just returns a null object when it finds a username in the ASP Membership without having related data in the DNN Users table.
The reason why the ASP aspnet_Users table and the DNN Users table were out of sync in my case (but there might be other reasons as well!) was that I have forgotten to clean up the ASP membership tables (e.g. aspnet_Users table) before (re-)installing a new DNN instance.
Solutions
In my case it was enough to delete the non-synchronized username from the ASP Membership tables (in my case it has been “host” and “admin” that have been created by default along the previously failed installation) as follows:
1. From the aspnet_Applications table determine the ApplicationID of your current application.
2. With this ApplicationID determine the UserIDs of your problematic (out of sync) usernames (in my case : “host” and “admin”)
3. Knowing these UserIDs delete the such related records from the following tables (mind the sequence to comply with referential integrity):
- Aspnet_Membership
- Aspnet_Profile
- Aspnet_UsersInRoles
- Aspnet_Users
That’s it
Pending issues and recommendation for improvement
Although it is absolutely my fault that has caused the problem here (not deleting old data from previous installations) there might be other reasons why the ASP Mebership tables (e.g aspnet_Users and the DNN pairs (e.g bsDev_Users) will be out of sync àGeneric issue.
So, instead of displaying a (more or less meaningless, hard to understand) exception message, it would be better to handle this issues more defensive.
A possible solution could be to still display all the UserNames that can be fetched from either the ASP or DNN User tables and then highlighting the ones that are out of sync.