MapTool creates lots of exceptions

662
7
01-25-2023 05:46 AM
Vidar
by
Occasional Contributor II

I have a maptool where I just place a marker on a map. Nothing else, no other business logic.

The marker is placed fine, however - when you look at the debug the amount of exceptions thrown from ArcGIS.Dektop.Mapping.dll is concerning.

What is going on here, should this be happening?

 

Vidar_0-1674654169321.png

Here is my simple code:

internal class FooTool : MapTool
{
    private IDisposable _graphic = null;

    public FooTool()
    {
        IsSketchTool = true;
        SketchType = SketchGeometryType.Point;
        SketchOutputMode = SketchOutputMode.Map;
    }

    protected override async Task<bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry)
    {
        try
        {
            MapPoint mapPoint = (MapPoint)geometry;

            await QueuedTask.Run(() =>
            {
                var mapView = MapView.Active;
                //Show marker
                if (_graphic != null)
                {
                    _graphic.Dispose();
                }
                _graphic = mapView.AddOverlay(mapPoint, SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.BlueRGB, 14, SimpleMarkerStyle.Pushpin).MakeSymbolReference());
            });
        }
        catch (ArgumentException ae)
        {
            ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(ae.Message, "Tool error");
        }
        catch (Exception ex)
        {
            Log.Error(ex);
        }

        return true;
    }
}

 

 

 

Tags (1)
0 Kudos
7 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

I have copied your code and it works fine on ArcGIS Pro 3.0.3 and ArcGIS Pro SDK for .NET 3.0.0.36057

0 Kudos
Vidar
by
Occasional Contributor II

What Visual Studio are you using? I am on:

Vidar_0-1674656568494.png

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

Microsoft Visual Studio Enterprise 2022 (64-bit) - Current
Version 17.4.3

I think problem is in project or solution configuration.

0 Kudos
Vidar
by
Occasional Contributor II

Where do you begin with this sort of stuff?! I did the migration process, but who knows if its done it 100% right. It would seem it hasn't ported cleanly.  I really don't want to start remaking all over project again.

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

I have created new tool (with FooTool nam) in existing Esri community sample project (3.0), then copy/pasted your code inside existing FooTool class 

0 Kudos
Vidar
by
Occasional Contributor II

No I don't mean that. I mean my actual project/add-in. Its huge from version 2.x of Pro. If I have to start a new addin project and copy in all the code and start again - thats a real pain in the backside!

0 Kudos
GKmieliauskas
Esri Regular Contributor

I have solutions migrated from 2.x to 3.0, but I haven't issues like yours. Migration was painful to me too.

I have made all steps of migration documentation and repaired code changes.

Try to cleanup project. Check references of your project and etc.

0 Kudos