Hi everyone,
I have converted an ArcObjects SDK .NET application written in C# for creating PDF maps to an ArcGIS Pro add-in using the ArcGIS Pro SDK. Everything runs fine from within ArcGIS Pro but now I want to convert it to a standalone complied exe as the original is so I can run it from Windows Task Scheduler.
From my research, I understand that await QueuedTask.Run is only needed inside of Pro so I have been slowly removing these one function at a time in the order that each function runs.
Things work until I get to the function below which is supposed to open an aprx that I use as a template (has layout that I manipulate, layers loaded, etc.) and return a Project object which is used later in the code to retrieve a Map and a Layout.
public static Project GetProject()
{
try
{
string aprxFile = PATH_Aprx_template + "exhibit_map.aprx";
// Open the project
//Project project = Project.OpenAsync(aprxFile).Result;
//Project project = Project.OpenAsync(aprxFile).GetAwaiter().GetResult();
Project project = Project.OpenAsync(aprxFile);
// Check if the project is null (failed to open)
if (project == null)
{
Console.WriteLine("Failed to open the project.");
return null;
}
return project;
}
catch (Exception ex)
{
Console.WriteLine($"Error in GetProject: {ex.Message}");
return null;
}
}
The project refuses to compile in Visual Studio with an error of "cannot implicitly convert type System.Threading.Tasks.Task<ArcGIS.Desktop.Core.Project> to ArcGIS.Desktop.Core.Project at line
Project project = Project.OpenAsync(aprxFile);
As you can see, I tried a couple of other things that are commented out but those didn't work either.
I am using ArcGIS Pro 3.3 and Visual Studio 2022.
Can someone help me out?
Thanks,
Carlos