I'm in the process of moving from MM 2010 to MM 2019. It's going as well as can be expected. The changes have been minor... until I turned on security.
I got a null reference error from deep in the bowels of MM. It turns out that the error was thrown in mmSecurityManager.GetUserRoleDefaultFormAccess(Guid securityID, DataSet dsRoleSecurity, DataSet dsUserRoles, mmSecurityAccessFormLevel level).
The initial cause was when I called GetAccessLevelForm(object userPK, Guid securityID) and default parameters were created by MM and it was sent to the more precise implementation of GetAccessLevelForm(). It turns out, instead of getting the UserRole infomration, it passed a null.
public override mmSecurityAccessFormLevel GetAccessLevelForm(object userPK, Guid securityID)
{
// Original code
//return GetAccessLevelForm(userPK, securityID,
// oUserSecurity.GetUserSecurityByPK(userPK),
// oRoleSecurity.GetRolesSecurityByUser(userPK),
// null); // REALLY? just send a null???
// Fill UserRoles with roles for specified user
UserRoles oUserRole = new UserRoles();
// This is just a helper I use to make it easy to get data by foreign Key - use your favorite technique
oUserRole.GetDataByFK("UserFK", (int)userPK, oRole.TableName);
return GetAccessLevelForm(userPK, securityID,
oUserSecurity.GetUserSecurityByPK(userPK),
oRoleSecurity.GetRolesSecurityByUser(userPK),
oUserRole.DataSet); // Now we have real data to send.
}
Turns out the problem was not quite solved yet... It turns out that there is an error in GetUserRoleDefaultFormAccess.
protected override mmSecurityAccessFormLevel GetUserRoleDefaultFormAccess(Guid securityID, DataSet dsRoleSecurity, DataSet dsUserRoles, mmSecurityAccessFormLevel level)
{
mmSecurityAccessFormLevel result = level;
DataRowCollection rows = dsUserRoles.Tables[oRole.TableName].Rows;
foreach (DataRow item in rows)
{
// oRole.PrimaryKey is RolePK - that's not what is in UserRoles
//DataRow[] array = dsRoleSecurity.Tables[0].Select(
// oRoleSecurity.SecurityFKField + " = '" + securityID.ToString() + "' AND " +
// oRoleSecurity.RoleFKField + " = " + item[oRole.PrimaryKey].ToString());
// Change oRolePrimaryKey (RolePK) to oRoleSecurity.RoleFKFiield (RoleFK)
DataRow[] array = dsRoleSecurity.Tables[0].Select(
oRoleSecurity.SecurityFKField + " = '" + securityID.ToString() + "' AND " +
oRoleSecurity.RoleFKField + " = " + item[oRoleSecurity.RoleFKField].ToString());
if (array.Length == 0)
{
result = mmAppBase.DefaultSecurityAccessFormLevel;
break;
}
}
return result;
}
Hopefully this will help someone turning on security.
Jeff