Hello everyone,
I am writing some MS tests for a service i wrote, in which i create elements and add them to a given package. The same code works from an addin.
In my Test, i am trying to test my connector creation, in the test buildup, i create 2 elements of type "Requirement" and then i create a connector between them. During the creation of the elements i create(if not exists) a diagram and add diagram-object for each element.
Whats happening is when i create the second Element, the first element is unlinked from the package and the diagram during the created during creation of Element 1 also disappears.
If i open project in EA15 and search for all elements i can see the Element1 along with Element2 but i cant locate the Element1 in the project browser.
And because of this when i try to create a connector between the 2 Elements i get "System.Runtime.InteropServices.COMException (0x800403E9): Cannot update connector as either the Start or the End object is NULL"
When i am printing the ID, Name, other props of both the elements during creation of connector, i can can see they look all correct.
The code below is my create Element method. i call this twice to make the 2 elements
public bool CreateElement(...) {
parentPkg = CreateOrGetParentPkg(inputEle);
string eleType = inputEle.Type;
// name and type are passed are args to method
ele = parentPkg.Elements.AddNew(eleName, eleType);
// creating diagram
Diagram rootDiagram = CreateOrGetDiagram(parentPkg, parentPkg.Name);
parentPkg.Elements.Refresh();
parentPkg.Update();
// Add element to diagram - autogenerate position
DiagramObject diagramObject = (DiagramObject)rootDiagram.DiagramObjects.AddNew(GetDiagramObjectPosition(ele.Name.Length), "");
diagramObject.ElementID = ele.ElementID;
diagramObject.Update();
rootDiagram.Update();
rootDiagram.DiagramObjects.Refresh();
parentPkg.Update();
parentPkg.Diagrams.Refresh();
ele.Update();
}
Any pointers in figuring out why this is happening will be highly appreciated, thanks