Unable to call COM DLLs from C#

1

I am trying to call C++ and C# DLLs using COM from a C#(4.0) service. The DLLs have be registered on the same server (win2003) and are currently being called from a C++ service using COM without issue (over 100k times). The DLLs expose an interface "ExecuteTransaction" which takes two arguments.

When I try to call them from C# I see a range of different errors

The COM DLLs start but error out with:

- 0x800706be;The remote procedure call failed.;
8004d00a;[Microsoft][ODBC driver for Oracle]Failure enlisting in Resource Manager

Then the C# service will error with:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Operation aborted (Exception from HRESULT: 0x80000007)
   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

another C++ DLL will simply hang with the message inv the event log:

A MS DTC component has encountered an internal error. The process is being terminated. Error Specifics: A non-MS DTC XA Library threw an exception in function oerhms ntdll!KiFastSystemCallRet + 0x0 + 0xb837ce8

the code is

using System;
using System.Collections.Generic;
using System.Reflection;
using System.EnterpriseServices;
using System.Data;
using System.Threading;
using System.Runtime.InteropServices;

....
int orderId = 65827;
int datasetId = 119849;
object objBM = null;
System.Guid bmGuid = new Guid("{43AFB035-9CFF-11D3-859D-0008C729AAEA}");

Type objBMType = Type.GetTypeFromCLSID(bmGuid);
objBM = Activator.CreateInstance(objBMType);
object[] args = {orderId,datasetId};
object c = objBMType.InvokeMember("ExecuteTransaction", System.Reflection.BindingFlags.InvokeMethod, null, objBM, args);

Calling a C# COM+ dll also gives problems. The service will will error with

System.Reflection.TargetInvocationException: Exception has been thrown by the target   of an invocation. ---> System.Runtime.InteropServices.COMException: The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

The services and dlls are all on the same server. What am i doing wrong? Am i missing a using statement? I looked at examples on the WEB and tried then but all give same errors? It is interesting that the DLLs start but fail internally like if the way I am calling them is incorrect

c#
c++
com
invoke
asked on Stack Overflow Jun 27, 2012 by user722226 • edited Jun 27, 2012 by Iridium

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0