Creating Graphic Elements Issues

02-07-2020 09:06 AM
Occasional Contributor

I have come across several issues with Graphic Element creation in ArcGIS Pro SDK 2.5 - some of them have been in before although they have changed slightly at 2.5. I'll make a question for each one.

If I create and then set Name on many graphic elements whilst the layout is open then it crashes ArcGIS Pro - if I do it whilst the layout is closed then it's OK.

An unhandled exception of type 'System.NullReferenceException' occurred in ArcGIS.Desktop.Layouts.dll
Additional information: Object reference not set to an instance of an object.

Layout layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault()?.GetLayout();
            for (int i = 0; i < 100; i++)
                List<Coordinate2D> lineCoordinates = new List<Coordinate2D> { new Coordinate2D { X = i, Y = 0 }, new Coordinate2D { X = i, Y = 100 } };
                Polyline polylineTic = PolylineBuilder.CreatePolyline(lineCoordinates);
                CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1.0, SimpleLineStyle.Solid);
                GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, polylineTic, lineSym);
                CIMElement cimElement = lineElm.GetDefinition();
                cimElement.Name = "Line" + i;

Of course I can close the layout do the work and then reopen...


0 Kudos
2 Replies
Occasional Contributor

I can always make it crash when making and renaming a group.

Make a new project. Add a layout (leave it on the layout).

Layout layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault()?.GetLayout();
            GroupElement groupElement = LayoutElementFactory.Instance.CreateGroupElement(layout);
            CIMElement cimGroupElement = groupElement.GetDefinition();
            cimGroupElement.Name = "First Level Group";


0 Kudos
Esri Regular Contributor


Thank you for reporting this.  I can also reproduce the crash when I create the command in 2.4 and use in 2.5.  Again, its a regression and we will address it immediately in 2.6 and hopefully address in a 2.5 patch.

Jeff - Layout team

0 Kudos