Select to view content in your preferred language

Project.OpenAsync throws an exception

326
4
09-03-2024 02:32 AM
CarstenAndersson
Regular Contributor

I have a ArcGIS Pro Managed Configuration project in Visual Studio 2022. I want to open a .aprx file, when the application is ready. I override the OnApplicationReady method in the ConfigurationManager, so when the application is ready I call the Project.OpenAsync method with the desired project file. It throws the "Could not find Project Dock Pane".

I'm stumped on what to do to be able to open the project.

Any help would be appreciated 🙂

Tags (3)
0 Kudos
4 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

I would recommend adding dependency to config.daml file to ADCore where esri_core_projectDockPane resides:

<dependencies>
    <dependency name="ADCore.daml" />
</dependencies>

 

0 Kudos
CarstenAndersson
Regular Contributor

Hi 🙂

Thanks for the reply. I tried it, but with the same result. But, I got it to work by calling Project.OpenAsync synchronously. Not sure why an async method should be called without await, but it works so I will go on from here. Thanks 🙂

0 Kudos
CharlesMacleod
Esri Regular Contributor

try:

var window = Project.GetCatalogPane(true);
if (window != null)
{
 Project.OpenAsync(@"path_to_your_project");
}

In your application ready.  However, I dont quite follow the workflow. Your start page is being shown/ refreshing (asynchronously) for the purpose of selecting a project when u trigger opening of another project "underneath" it?

Anyway, this is probably a timing issue in that the application is refreshing the start page UI when u call OpenAsync.  If GetCatalogPane returns null u cld try building in a delay before invoking OpenAsync to allow the UI to complete its refresh. Something like "Task.Delay(500).Wait()" or whatever.

That said, the preferred way to open a project without selecting a project from the start page is to specify the project on the command line - as the last argument (ie after the "/config:xxxxxxx"). This will skip showing the start page entirely.

If u need to determine the project URI programmatically, and so cant use the cmd line, id suggest building in an event in your start page view model to fire after it  (ie the start page user control) is loaded - and have that event do the OpenAsync.

0 Kudos
CarstenAndersson
Regular Contributor

Thanks for the reply Charles.

The end user is not shown the start page. The system should automatically open a predetermined .aprx file. I suspect, just like you, that this could be a timing issue, even though I tried waiting for 5 seconds, but only to get the same result. Anyway, I got it to work by calling Project.OpenAsync synchronously (without await) - strange. Not sure why this is the case, but thanks for the reply 🙂

0 Kudos