COM Object Method Invoke Exception - Silverlight 4

Posted by Adam Driscoll on Stack Overflow See other posts from Stack Overflow or by Adam Driscoll
Published on 2010-05-04T17:32:17Z Indexed on 2010/05/04 17:58 UTC
Read the original article Hit count: 1661

I'm trying to use the new AutomationFactory provided with Silverlight 4 to call a .NET COM class.

.NET COM-Exposed Class:

public class ObjectContainer
{
    public bool GetObject([Out, MarshalAs((UnmanagedType.IUnknown)] out object obj)
    {
          obj = new SomeOtherObj();
          return true;
    }
}

Silverlight Assembly:

        dynamic objectContainer;

        try
        {
            objectContainer = AutomationFactory.GetObject(ProgId);
        } catch
        {
            objectContainer = AutomationFactory.CreateObject(ProgId);
        }

        object obj;

        if (!objectContainer.GetObject(out obj))
        {
            throw new Exception();
        }

When I call objectContainer.GetObject(out obj) an exception is thrown stating:

Value does not fall within the expected range.

at MS.Internal.ComAutomation.ComAutomationNative.CheckInvokeHResult(UInt32 hr, String memberName, String exceptionSource, String exceptionDescription, String exceptionHelpFile, UInt32 exceptionHelpContext) at MS.Internal.ComAutomation.ComAutomationNative.Invoke(Boolean tryInvoke, String memberName, ComAutomationInvokeType invokeType, ComAutomationInteropValue[] rgParams, IntPtr nativePeer, ComAutomationInteropValue& returnValue) at MS.Internal.ComAutomation.ComAutomationObject.InvokeImpl(Boolean tryInvoke, String name, ComAutomationInvokeType invokeType, Object& returnValue, Object[] args)
at MS.Internal.ComAutomation.ComAutomationObject.Invoke(String name, ComAutomationInvokeType invokeType, Object[] args) at System.Runtime.InteropServices.Automation.AutomationMetaObjectProvider.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result) at System.Runtime.InteropServices.Automation.AutomationMetaObjectProviderBase.<.cctor>b__4(Object obj, InvokeMemberBinder binder, Object[] args) at CallSite.Target(Closure , CallSite , Object , String , Object& ) at CallSite.Target(Closure , CallSite , Object , String , Object& ) at ApplicationModule.ObjectContainer.GetObject()

Wha's the deal?

© Stack Overflow or respective owner

Related posts about com-interop

Related posts about c#