origam.com

An item with the same key has already been added Key:1

I’ve several lazy loaded screens. Some of the fields on master and detailed parts are calculated based on custom user-defined functions. When I’m clicking on different records on master screen to quickly I got this error. When I’m slow enough, the error is not shown.
image
The server log shows:

2021-10-18 10:12:15,670 [123] ERROR Origam.ServerCore.Controller.AbstractController - An item with the same key has already been added. Key: 1
System.ArgumentException: An item with the same key has already been added. Key: 1
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Origam.Server.SessionStore.GetRowsFromStore(String entity, IEnumerable ids) in D:\a\1\s\origam-source\Origam.ServerCommon\Session Stores\SessionStore.cs:line 1448
   at Origam.Server.SessionStore.RowStatesForDataLessSessions(String entity, Object[] ids, Object profileId) in D:\a\1\s\origam-source\Origam.ServerCommon\Session Stores\SessionStore.cs:line 1392
   at Origam.Server.SessionStore.RowStates(String entity, Object[] ids) in D:\a\1\s\origam-source\Origam.ServerCommon\Session Stores\SessionStore.cs:line 1386
   at Origam.ServerCore.ServerCoreUIService.RowStates(RowStatesInput input) in D:\a\1\s\origam-source\Origam.ServerCore\ServerCoreUIService.cs:line 438
   at Origam.ServerCore.Controller.UIServiceController.<>c__DisplayClass19_0.<RowStates>b__0() in D:\a\1\s\origam-source\Origam.ServerCore\Controller\UIServiceController.cs:line 189
   at Origam.ServerCore.Controller.AbstractController.RunWithErrorHandler(Func`1 func) in D:\a\1\s\origam-source\Origam.ServerCore\Controller\AbstractController.cs:line 120

The above pull request fixes the problem you have encountered. However there is a bigger problem in the model. The screen cannot work the way it is set up right now because it is backed by a view in the SQL server and the primary key there is a detached field.
This leads to problems when trying to get row states for the rows.

The primary key will have to be a real filed. @washi can provide more details if needed.

I just add - if the screen is lazy loaded it cannot have a virtual primary key as it used to. Either it must be set to load all data and then it will work or it has to have a real primary key in the view so the client can load the row again e.g. when user clicks on it etc.