Strange behavior when working with tasks in ArcGIS Pro and C#

599
2
08-09-2018 05:14 AM
CarstenAndersson
Regular Contributor

Hi.

I've noticed something strange when developing a C# add-in for ArcGIS Pro.

I've created one task item with two task "inside".

I want to iterate through the list of tasks, like so:

var taskItem = Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();

TaskItemInfo taskItemInfo = taskItem.GetTaskItemInfo(); // <-- This line is throwing the NullReferenceException

IEnumerable<TaskInfo> taskInfos = taskItemInfo.GetTasks();

foreach (TaskInfo taskInfo in taskInfos)
{

   // do something
}

But the 2nd line is throwing an exception. I don't understand why. I've actually taken the code from ArcGIS Pro 2.2 API Reference Guide with the same result. I don't get it. 

Any help would be greatly appreciated

Tags (2)
0 Kudos
2 Replies
NarelleChedzey
Esri Contributor

Hi Carsten, 

Unfortunately this is a bug.  If you ensure you have the task pane open when you run this code, it should succeed. 

I have added an issue to our backlog to fix this for the next release. 

Sorry for the inconvenience. 

Narelle

CarstenAndersson
Regular Contributor

Hi Narelle.

Thanks a lot for the reply  I will look forward to the fix.

Carsten

0 Kudos