This project is read-only.

Error: An item with the same key has already been added.

Topics: Business Logic Layer, Themes
Jan 12, 2014 at 2:48 PM
Edited Jan 12, 2014 at 2:51 PM
I just created a test account and gave that test user "Editor" role after that suddenly I am getting this error in my project:
Server Error in '/' Application.

An item with the same key has already been added. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: An item with the same key has already been added.

Source Error: 

Line 646:                            while (rdr.Read())
Line 647:                            {
Line 648:                                rightsWithRoles.Add(rdr.GetString(0), new HashSet<string>(StringComparer.OrdinalIgnoreCase));
Line 649:                            }
Line 650:                        } 

Source File: c:\Users\Downloads\Projects\BlogEngine29\blogengine_2ac107166b4e\BlogEngine\BlogEngine.Core\Providers\DbBlogProvider.cs    Line: 648 

Please help ?

FYI: I have this test user 2 roles.
Jan 13, 2014 at 9:17 PM
anyone ?
Jan 14, 2014 at 9:05 PM
Please help with this issue ?
Jan 14, 2014 at 9:49 PM
Check table it is pulling data from, you probably got duplicate records for Editor you need to delete.
Apr 30, 2015 at 7:56 AM
Edited May 1, 2015 at 3:21 PM
I've posted a solution here:
Even if the duplicates are not in the same table Using the same general approach would work.

delete be_Rights

FROM be_Rights

left outer join (

select min(RightRowId) as rowId, BlogId, RightName

from be_Rights

group by BlogId, RightName) as keepRows on

be_Rights.RightRowId = keepRows.rowId

where keepRows.rowId is null

delete be_Settings

FROM be_Settings

left outer join (

select min(SettingRowId) as rowID, BlogId, SettingName

from be_Settings

group by BlogId, SettingName) as keepRows on

be_Settings.SettingRowId = keepRows.rowID

where keepRows.rowID is null