COM Object Method Invoke Exception - Silverlight 4
- by Adam Driscoll
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.<.cctorb__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?