Esri ArcObjects .NET SDK 10.4 Autogenerated code for Construction Tool throws System.Runtime.InteropServices.COMException when Debugging

0

I'm currently writing a plugin for ArcMap 10.4 using the .NET framework. I'm using the latest ArcGIS Runtime SDK for .NET (100.2.1) and the 10.4 ArcObjects SDK. I'm developing on a Windows Server 2016 Standard Edition (Version 1607) virtual machine, with a 64-bit OS and processor.

I've used the ArcMap Add-In Wizard to autogenerate a Construction Tool with the Polygon type, and added the necessary code in my Config.esriaddinx to add that tool to a toolbar. I haven't made any changes to the autogenerated C# code.

The project is set up to debug through ArcMap and attach to the process, as automatically setup by the wizard. All of this works fine: The debugger starts, there is a button on the toolbar that brings up a Windows Form, everything functions as normal. The problem comes when I try to click the button on the toolbar corresponding to the Construction Tool:

enter image description here

This button, when clicked, calls into the autogenerated OnActivate() method of the Construction Tool:

protected override void OnActivate()
        {
            m_edSketch = m_editor as IEditSketch3;

            // Activate a shape constructor based on the current sketch geometry
            if (m_edSketch.GeometryType == esriGeometryType.esriGeometryPoint | m_edSketch.GeometryType == esriGeometryType.esriGeometryMultipoint)
                m_csc = new PointConstructorClass();
            else
                m_csc = new StraightConstructorClass();

            m_csc.Initialize(m_editor);
            /* TODO: This is auto-generated code... Why does this throw an exception??? */
            m_edSketch.ShapeConstructor = m_csc;
            m_csc.Activate();

            // Setup events
            m_editEvents.OnSketchModified += OnSketchModified;
            m_editEvents5.OnShapeConstructorChanged += OnShapeConstructorChanged;
            m_editEvents.OnSketchFinished += OnSketchFinished;
        }

This is the method where the exception is thrown. At the line

m_edSketch.ShapeConstructor = m_csc;

The following exception is thrown:

Error HRESULT E_FAIL has been returned from a call to a COM component.
Error Code: -2147467259
Trace:
at 
ESRI.ArcGIS.Editor.IEditSketch3.set_ShapeConstructor(IShapeConstructor ShapeConstructor)
at AddIn.ConstructionTool.OnActivate() in 
C:\...\ConstructionTool.cs:line 50

This exception doesn't really have much to say, especially since the HRESULT error code resolves to an unspecified failure (0x80004005). It feels especially weird that it's being thrown here, as well, because this is autogenerated code and all we're doing is setting a value.

Any idea why this exception is being thrown? Could this perhaps be a version mismatch between the ArcGIS Runtime and ArcObjects SDK? Is there some .dll missing from my Windows Machine that the ArcObjects SDK is expecting to be here? Has anyone run into similar problems and found workarounds?

Commenting out the line throwing the exception allows things to run without error, but the tool does not work and no lines are drawn.

Any help at all here would be useful.

c#
.net
arcgis
arcmap
arcobjects
asked on Stack Overflow Mar 27, 2018 by Jake Meacham

1 Answer

0

Try changing the embed interop types property to false, in your project references for all the esri references

when that property is set to true it causes problems

answered on Stack Overflow Sep 20, 2018 by yedidya sulzbacher

User contributions licensed under CC BY-SA 3.0