Select to view content in your preferred language

Creating ArcGIS Pro addin - Cannot evaluate expression because the current thread is in a stack overflow state

2035
6
08-19-2023 04:32 PM
ChrisCrowe1
Emerging Contributor

I am running Visual Studio 2022 - Version 17.7.1

I am running ARC GIS pro 3.1.0

I created a simple c# addin from the ArcGIS Pro Module Addin from a template in Visual Studio.

I added a button and in the onclick event I have this code

protected override void OnClick()
       {
               //Get the active map view.
               var mapView = MapView.Active;
               if (mapView == null)
                   return;
       }

 This code works and I can see properties of the mapView if I set a breakpoint.

ChrisCrowe1_0-1692487465405.png

However I can't call the method below since it needs to be run on the main thread.

var selectedFeatures = mapView.Map.GetSelection();

Changing my code to the following and using QueuedTask.Run allows this to work and it does indeed flash the selected object.

protected override void OnClick()
       {
           QueuedTask.Run(() =>
           {
               //Get the active map view.
               var mapView = MapView.Active;
               if (mapView == null)
                   return;
 
               var selectedFeatures = mapView.Map.GetSelection();
 
               //Flash the collection of features.
               mapView.FlashFeature(selectedFeatures);
           });
       }

 But if I put a breakpoint within the QueuedTask.Run body I get a stack overflow error when trying to view most object properties 

ChrisCrowe1_1-1692487719240.png

 

So the code works but I cant see any properties while debugging. I have no idea what is causing this and hence I can't actually write my plugin.

Cannot evaluate expression because the current thread is in a stack overflow state.

Hopefully someone has an idea?

 

6 Replies
ChrisCrowe1
Emerging Contributor

OK I decided to find a sample and test with that.

I went to git hub and found the Simple Point Plugin - https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Plugin/SimplePointPluginTest

I downloaded the files and only changed the path to the sample.

I ran it in Visual Studio 2022 and put a breakpoint at line 57 in TestCSV1.cs

ChrisCrowe1_0-1692497542266.png

I then added a watch variable for MapView.Active.Map.GetSelection()

ChrisCrowe1_2-1692498101861.png

 

Exactly the same issue. So, I at least know it is not just my code showing this issue. But no further ahead.

 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

This is a problem that has been identified with the 3.1 release and resolved for the 3.2 upcoming release.  The cause was an issue with defining a custom stack size when managed threads and native threads are mixed.   This issue was resolved in the underlying architecture of ArcGIS Pro and is therefore not suited for a 3.1 patch release.

0 Kudos
ChrisCrowe1
Emerging Contributor

@Wolf wrote:

This is a problem that has been identified with the 3.1 release and resolved for the 3.2 upcoming release.  The cause was an issue with defining a custom stack size when managed threads and native threads are mixed.   This issue was resolved in the underlying architecture of ArcGIS Pro and is therefore not suited for a 3.1 patch release.


Thanks @Wolf good to know. 

Cheers

 

0 Kudos
BillBott
Frequent Contributor

Is it possible it can be reconsidered for a 3.1 patch release? Our teams work with the supported Network Management release. and consequently, won't be moving to 3.2 anytime soon. This fix would be very helpful for developers working under these conditions. 

 

RalfSchmidt
Occasional Contributor

Hi @Wolf ,

Please add me to the list of people who need a 3.1 patch for the issue "Cannot evaluate expression because the current thread is in a stack overflow state."

Cheers, Ralf

P.S.: Würde es helfen, wenn ich den Wunsch auf deutsch wiederhole? 😉

RalfSchmidt
Occasional Contributor

In case somebody is interest: Our customer reported this issue to Esri support and it now has an official bug number:

BUG-000162862: Message "Cannot evaluate expression because the current thread is in a stack overflow state." happens while debugging certain variables in threads in ArcGIS Pro SDK 3.1

Our customer currently does not plan to escalate this issue. Nevertheless, if you contact Esri support and let yourselves be add to the list of customers effected by this issue, maybe Esri decides to put a fix for it into ArcGIS Pro 3.1.

0 Kudos