Select to view content in your preferred language

Standa-alone .exe: Cannot run CoreHost sample, "External component has thrown an exception."

426
0
08-15-2024 08:51 AM
AZendel
Frequent Contributor

I'm trying to build a stand-alone WinForms exe application. My code ran into trouble when trying to connect to an Enterprise Geodatabase (Oracle), so I tried connecting to a File Geodatabase and got the same error messages. To troubleshoot, I downloaded this Sample: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/CoreHost/CoreHostSample 

I double clicked the CoreHostSample.sln file to open the project (I didn't create a fresh project and import the code).

I also downloaded the sample FGDB and put it in the specified location: C:\Data\SDK.gdb. I got the same error when I try to connect to that FGDB on line 84: "External component has thrown an exception.".  The VS output window shows this: 'System.Runtime.InteropServices.SEHException' in ArcGIS.Core.dll

I stepped into the line with Host.Initialize(); (that's line 77) and no issues seemed to arise. 

I added C:\Program Files\ArcGIS\Pro\bin to the system PATH variable.

I tried setting ArcGIS.Core.dll and ArcGIS.CoreHost.dll to "Copy Local"

I've ensured that the four conditions under the "Initialize sequence" section of this article are met.

After calling Host.Initialize(), I've looped through the available licenses using

 

foreach (LicenseCodes lc in Enum.GetValues(typeof(LicenseCodes)))

 

It spits out that Network Analyst, Analyst 3D and Spatial Analyst are all available (with non of the other extension licenses being available). The below returns "License level: Advanced"

 

LicenseLevels ll = LicenseInformation.Level;
string ll_str = Enum.GetName(typeof(LicenseLevels), ll);
printMore += "License level: " + ll_str + "\n";

 

The ArcGIS Pro SDK is installed. I'm on Pro 3.0.3 (we reportedly can't upgrade to do incompatibilities with the current (out-dated) version of ArcGIS Server our county uses).

I copied the entire block starting with line 84 into an VS 2022 Pro add-in project and I could connect to the FGDB with no errors thrown. So I think it has something to do with this stand alone exe. 

I want my application to not be an add-in because 90% of it has nothing to do with GIS - I just need to make a few spatial queries. And developing a Pro add-in gets a bit frustrating because you have to re-launch Pro and then open a project every time you want to start a debug process (if there's a way around that, please let me know!).

Any help would be appreciated! Thanks!

Secondary question: can I use the Pro SDK in a Windows "Forms" application (not console, not WPF)? This suggests that I can't. As mentioned, this is not an add-in and I will not be using any type of ArcGIS 'controls' on my forms. I just need to 1) connect to our Enterprise GeoDatabase, 2) select a polygon, 3) Buffer that polygon, 4) select the parcels that intersect the buffer, 5) loop through the parcels and extract attributes. Even if I can't use WinForms, I still can't get the console app to run.... 

0 Kudos
0 Replies