Select to view content in your preferred language

Calling an ArcMap extension(add-in) method from another ArcMap extension(add-in)

577
0
01-16-2024 06:05 AM
vsevgu
by
Emerging Contributor

I have a third-party ArcMap extension (codes not available) is SomeException.
This extension implements the IExtension, IExtensionConfig, IPersistVariant and ISomeInterface interfaces
I'm calling SomeException methods from another ArcMap extension.

On a Windows 10 machine running ArcGis 10.5, the ISomeInterface methods are available from my extension and (SomeException is ISomeInterface) = true.
On a Windows 8 machine running ArcGis 10.2, ISomeInterface methods are not available from my extension and (SomeException is ISomeInterface) = false.
The IExtension, IExtensionConfig, IPersistVariant interfaces are always available.

What could be the problem?

Perhaps ISomeInterface 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 ISomeInterface 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 ISomeInterface

 

 

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 ISomeInterface

 

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 Kudos
0 Replies