ArcPro 2.6 SDK Core Dump

252
3
09-01-2020 03:26 PM
JeffBoyton
New Contributor II

In ArcPro 2.6 (and 2.6.1), this code snippet will core dump (it works in 2.5).  This is a much simplified version of a larger Add-In.  Is this a known issue?  Is there a way around this core dump (without altering the steps it requires)?

protected async override void OnClick()
{
   await QueuedTask.Run(() =>
   {
      string mapName = $"Map-Copy";

      //Get the map
      MapProjectItem mapProjectItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name == "Map");
      Map originalMap = mapProjectItem.GetMap();

      // Make a copy of the map
      Map newMap = MapFactory.Instance.CopyMap(originalMap);
      newMap.SetName(mapName);
      SpatialReference spatialReference = SpatialReferenceBuilder.CreateSpatialReference(6455);

      // Get the map frame in the layout
      LayoutProjectItem layoutProjectItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name == "Layout");
      Layout layout = layoutProjectItem.GetLayout();
      MapFrame frame = layout.Elements.FirstOrDefault(e => e.Name == "Map Frame") as MapFrame;

      //Set the map frame's map to the new copy
      frame.SetMap(newMap);

      // Change the spatial reference of the map
      newMap.SetSpatialReference(spatialReference);
   });
}

0 Kudos
3 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

When i moved the last line:  newMap.SetSpatialReference(spatialReference) to a line before the map is assigned to the mapframe it worked:

protected override async void OnClick()
{
		try
		{
				await QueuedTask.Run(() =>
				{
						string mapName = $"Map-Copy";
						//Get the map
						MapProjectItem mapProjectItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name == "Map");
						Map originalMap = mapProjectItem.GetMap();
						// Make a copy of the map
						Map newMap = MapFactory.Instance.CopyMap(originalMap);
						newMap.SetName(mapName);
						SpatialReference spatialReference = SpatialReferenceBuilder.CreateSpatialReference(6455);
						// Change the spatial reference of the map
						newMap.SetSpatialReference(spatialReference);

						// Get the map frame in the layout
						LayoutProjectItem layoutProjectItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name == "Layout");
						Layout layout = layoutProjectItem.GetLayout();
						MapFrame frame = layout.Elements.FirstOrDefault(e => e.Name == "Map Frame") as MapFrame;

						//Set the map frame's map to the new copy
						frame.SetMap(newMap);
				});
		}
		catch (Exception ex)
		{
				MessageBox.Show($@"Exception: {ex}");
		}
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
JeffBoyton
New Contributor II

Yes, but my program does not know what the spatial reference will be until after the map frame is updated.  Setting the map frame to the map copy happens very early in the process and setting the map's spatial reference happens much latter in the process.

0 Kudos
JeffBoyton
New Contributor II

Are you able to catch this exception?  No matter where I put the try (inside or outside the QueuedTask) Visual Studio jumps to a 'stopped execution'.

0 Kudos