Error when accessing ArcMap extension(add-in) methods

24 views Asked by At

I have a third-party ArcMap extension (codes not available) is SomeException. This extension implements the IExtension, IExtensionConfig, IPersistVariant and ICustomInterface interfaces I'm calling SomeException methods from another ArcMap extension. ICustomInterface is a custom interface.ICustomInterface is implemented inside SomeExtension class.

On a Windows 10 machine running ArcGis 10.5, the ICustomInterface methods are available from my extension and (SomeException is ICustomInterface) = true.

On a Windows 8 machine running ArcGis 10.2, ICustomInterface methods are not available from my extension and (SomeException is ICustomInterface) = false.

The IExtension, IExtensionConfig, IPersistVariant interfaces are always available.

What could be the problem?

Perhaps ICustomInterface is not a COM interface. I don't know whether the SomeException extension class has the ComVisible(true) attribute or not.

Is there any way to make all interfaces of the SomeException extension available at the OS level?

On a Windows 8 machine running ArcGis 10.2, the ICustomInterface interface can be accessed by declaring the COM extension object as dynamic. For example:

        var extClass = new UIDClass();
        extClass.Value = "{XXXXX-XXX...}";
        dynamic someExt = _application.FindExtensionByCLSID( extClass);

        someExt.SomeMethod(); //method of ICustomInterface

If SomeMethod has no parameters, then the call occurs correctly. If SomeMethod has a class among its parameters, an error occurs. For example, such a call to the method

 someExt.SomeMethod_2(someClass);  //method 2 of ICustomInterface

is the following error:

    System.InvalidCastException: Failed to cast object type 'System.__ComObject' to type 'someClass'.    in System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
      in System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
   in CallSite.Target(Closure , CallSite , ComObject , JOB )
   in System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   in CallSite.Target(Closure , CallSite , Object , JOB )
   in System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)

How can I call SomeMethod_2 correctly?

0

There are 0 answers