Version: 19.4.0.50
The above function complains of duplicate keys.
Context:
I have a singleton datasource that may be updated on a seperate page, so i would like to redraw the component with existing data on a page.
In my page I call AddDiagramElements fine the first time the page is hit in OnAfterRender ()
On second call, if i dont call this, the diagram is empty. If i do call, it complains of duplicate keys.
Stack Trace
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'yXoqvV-8VHG_sK9WUkTxTbD1CYtbDBSXIsYMmC8HleY'.
System.ArgumentException: An item with the same key has already been added. Key: C_09B_09A_2
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at Syncfusion.Blazor.Diagram.Internal.DiagramLayerContent.InitConnector(Connector obj, Boolean independentObj)
at Syncfusion.Blazor.Diagram.Internal.DiagramLayerContent.InitObject(Object element)
at Syncfusion.Blazor.Diagram.Internal.DiagramLayerContent.InitLayerObjects()
at Syncfusion.Blazor.Diagram.Internal.DiagramLayerContent.InitObjects()
at Syncfusion.Blazor.Diagram.Internal.DiagramLayerContent.LoadDiagram(Boolean isSerialize)
at Syncfusion.Blazor.Diagram.Internal.DiagramLayerContent.OnScriptRendered()
at Syncfusion.Blazor.Diagram.SfDiagramComponent.OnAfterScriptRendered()
at Syncfusion.Blazor.SfBaseComponent.OnAfterRenderAsync(Boolean firstRender)
at Syncfusion.Blazor.Diagram.SfDiagramComponent.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
The interesting thing to note is the KEY is unique which includes the page load count, eg the _2 on the end of the above indicates the second call to the AddDiagramElements function, and as such.
I have confirmed my elements are not duplicates with:
var distinctElements = elements.Select(e => e.ID).Distinct().ToList();
if(elements.Count != elements.Distinct().Count)
{
Logger.LogError("Duplicate Nodes Found"); // this never triggers
}
var addTask = NavDiagram.AddDiagramElements(elements);
|
diagram.ClearSelection();
collectionNew = new DiagramObjectCollection<NodeBase>();
Connectors.Clear();
Nodes.Clear(); |
Thanks for the quick reply, this does clarify some things regarding node add/remove.
Manually pressing the button is not what im after.
I'm looking to understand how to get the nodes to load automatically each time the page is hit.
First time there may be a lengthy asyncronous data load as described previously with the singleton data source which is also used to render a treegrid on the same page.
Subsequent loads much faster using cache.
Dont really have a sample as your sample is about as far as ive got ( with code that will compile for you to test)
|
<SfDiagramComponent Width="100%" Height="700px" @ref="diagram" Nodes="@Nodes" Connectors="@Connectors" Created="created">
</SfDiagramComponent>
public async Task created()
{
await AddElements();
} |