DotNetNuke Exception in DotNetNuke.Entities.Users.UserInfo.get_Social()

352 views Asked by At

just recently started getting a "System.ArgumentException: An item with the same key has already been added." with the following stack trace.

System.ArgumentException: An item with the same key has already been added
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at DotNetNuke.Entities.Users.UserInfo.get_Social()
   at DotNetNuke.Entities.Users.UserInfo.get_Roles()
   at DotNetNuke.Entities.Users.UserInfo.IsInRole(String role)
   at DotNetNuke.HttpModules.Membership.MembershipModule.AuthenticateRequest(HttpContextBase context, Boolean allowUnknownExtensinons)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

All I did was install and update Extensions and recycle the application pool. It appears on different pages where I have a custom module that has a search form on it and some DevExpress components.

DNN Version is 7.3.2

Kind regards

UPDATE: Seems to be a bug in DNN https://dnntracker.atlassian.net/browse/DNN-6990

1

There are 1 answers

0
samy On

I think you are seeing a race condition where two threads are trying to access the Social property of the UserInfo:

public UserSocial Social
{
    get
    {
        if (this._social == null)
        {
            this._social = new Dictionary<int, UserSocial>();
        }
        if (!this._social.ContainsKey(this.PortalID))
        {
            this._social.Add(this.PortalID, new UserSocial(this));
        }
        return this._social[this.PortalID];
    }
}

The only way for the error to happen would be for two threads to check the presence of the portal id key and both trying to add the key to the dictionary at the same time.

The Social property is called in many places (14 according to ILSpy in a v7.2.2), so it is hard to pinpoint where the problem could be coming from; if you note that the problem occurs only with your custom module you may want to investigate the methods that may call this code