CodeNameNotUniqueException after applying hotfix Kentico 7

geoff l asked on July 11, 2016 02:10

Hi,

I am having a 'CodeNameNotUniqueException' error whereby after upgrading from v7.0.37 to v7.0.70 I am getting an error on loading my website. It looks like it is related to something to do with roles as the code name 'int-sg-ctx-nz-xa6-publisheddesktopoffice2013' is a role in my website. It basically happens to all the roles and not just this one. This is the error message that I get in event viewer:

Code
Exception information: 
Exception type: CodeNameNotUniqueException 
Exception message: The object with code name 'int-sg-ctx-nz-xa6-publisheddesktopoffice2013' already exists.
at CMS.DataEngine.AbstractInfoProvider`2.SetInfoInternal(InfoType info)
at CMS.DataEngine.AbstractInfoProvider`2.SetInfo(InfoType info)
at CMS.SiteProvider.UserInfoProvider.EnsureRolesAndSitesInternal(UserInfo uInfo, Boolean isWindowsAuth)
at CMS.CMSHelper.AuthenticationHelper.EnsureExternalUser(UserInfo uInfo)
at CMS.CMSHelper.AuthenticationHelper.AuthenticateWindowsUser(String userName, SecurityIdentifier sid, String siteName, String[] roles)
at CMS.CMSHelper.ContextData.GetCurrentUser(Boolean& loadUserData, Boolean cacheResult)
at CMS.CMSHelper.ContextData.get_CurrentUser()
at CMSAppBase.CMSSessionStart(Object sender, EventArgs e)
at System.Web.SessionState.SessionStateModule.CompleteAcquireState()
at System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Request information: 
    Request URL: http://aainsurance/CMSPages/PortalTemplate.aspx?aliaspath=/home 
    Request path: /CMSPages/PortalTemplate.aspx 
    User host address: 10.212.210.58 
    User: INT\U362515 
    Is authenticated: True 
    Authentication Type: NTLM 
    Thread account name: IIS APPPOOL\AAI.Intranet 

Thread information: 
    Thread ID: 58 
    Thread account name: IIS APPPOOL\AAI.Intranet 
    Is impersonating: False 
    Stack trace:    at CMS.DataEngine.AbstractInfoProvider`2.SetInfoInternal(InfoType info)
    at CMS.DataEngine.AbstractInfoProvider`2.SetInfo(InfoType info)
    at CMS.SiteProvider.UserInfoProvider.EnsureRolesAndSitesInternal(UserInfo uInfo, Boolean isWindowsAuth)
    at CMS.CMSHelper.AuthenticationHelper.EnsureExternalUser(UserInfo uInfo)
    at CMS.CMSHelper.AuthenticationHelper.AuthenticateWindowsUser(String userName, SecurityIdentifier sid, String siteName, String[] roles)
    at CMS.CMSHelper.ContextData.GetCurrentUser(Boolean& loadUserData, Boolean cacheResult)
    at CMS.CMSHelper.ContextData.get_CurrentUser()
    at CMSAppBase.CMSSessionStart(Object sender, EventArgs e)
    at System.Web.SessionState.SessionStateModule.CompleteAcquireState()
    at System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData)
    at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Custom event details: 

Can anyone help with this? As of now I've had to rollback the database and restore the files for version 37 which is a shame as this version is not fully compatible with IE11.

Recent Answers


Trevor Fayas answered on July 11, 2016 20:07

During the upgrade the rule may have changed from not requiring unique to requiring unique. I would go through your roles in the database and see what ones aren't unique, and then you may have to adjust them. Hopefully nothing else is referencing them by code name.

0 votesVote for this answer Mark as a Correct answer

geoff l answered on July 11, 2016 23:33

Thanks for your response Trevor. Unfortunately, the names are all unique so I was puzzled by this too.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on July 12, 2016 00:06

sorry then :( may want to contact kentico support if no one else is able to chime in an idea.

0 votesVote for this answer Mark as a Correct answer

geoff l answered on August 1, 2016 05:35

I have managed to fix this by putting in the line AuthenticationHelper.ImportExternalRoles = false; in the CMSAppBase.cs file. Context shown below:

if (siteName != "")
{
    // If authentication mode is Windows, set user UI culture
    if (RequestHelper.IsWindowsAuthentication() && UserInfoProvider.IsAuthenticated())
    {
        AuthenticationHelper.ImportExternalRoles = false; // LINE INSERTED HERE TO FIX ISSUE
        UserInfo currentUser = CMSContext.CurrentUser;
        if (!currentUser.IsPublic())
        {
            UserInfoProvider.SetPreferredCultures(currentUser);
        }
    }
}

I guess what this does is it prevents external roles being imported into the CMS_Role table. However, this is not really desired if possible as we would still want roles to be imported. We weren't having issues without this setting being set to false in the previous version so is there something in the newer versions which is importing external roles in a different way that is causing a 'CodeNameNotUniqueException'?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.