TargetInvokationException...COMException (0x80010007)

G

Gemma M

Hi,

I have a C# program (code fragment below), which runs forever, processing
incoming jobs. Part of this program launches a COM object. However, after
a while I get :

System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x80010007): Automation error

Does anyone know what can be causing this problem?

Is there other house-keeping, garbage collection, and/or memory management
things I can do to prevent what I'm assuming to be exhaustion of resources?

I am running Framework 1.1.4322 SP 1.

I load the COM object using :
// -- Create the COM Active X DLL. --
activityType = Type.GetTypeFromProgID(act.ModuleName);
activityInstance = Activator.CreateInstance(activityType);

I unload the COM object using :
while (Marshal.ReleaseComObject(activityInstance) > 0) {

Thanks in advance
G

--------------------------------------------- Code Fragment.---------
Actvivity (the argument for this method) is an object containing text
fields.

// --------------------------------------------------------------------
/// <summary>
/// Given the name of a registered COM ActiveX DLL, this method
/// loads it and attempts to run the action therein.
/// </summary>
/// <param name="activeXName"></param>
/// <returns></returns>
// --------------------------------------------------------------------
public bool COMRunActiveXDll(Activity act) {

bool rv = false; // Return value.
string whoAmI =
Service.IN_WHAT + "COMRunActiveXDLL" + this.currentInstance;

// - The .NET type equivalent to the named COM DLL. -
Type activityType = null;

// - Instance of COM DLL. -
object activityInstance = null;

// - Arguments for the call to the method within the COM DLL. -
object[]activityArguments = null;

// - LastError property of active X dll. -
string activityError = "";

try {

if (act != null) {

// -- Create the COM Active X DLL. --
activityType = Type.GetTypeFromProgID(act.ModuleName);
activityInstance = Activator.CreateInstance(activityType);

// -- Now create the list or arguments for the activity. --
activityArguments = new object[] {act.CaseId, act.StateId,
act.Argument};

// -- Run the activity. --
rv = (bool) activityType.InvokeMember("Action",
BindingFlags.InvokeMethod, null,
activityInstance, activityArguments);

if (rv == false) {

activityError = (string)
activityType.InvokeMember("LastError",
BindingFlags.GetProperty, null, activityInstance, null);
this.lastError = whoAmI + ": COM ActiveX failed. " +
activityError;
this.Logger.PostMessage(this.LastError,
SyslogMessageSeverity.SLOG_WARNING, whoAmI);

} // if (rv...

} // if (act...

} catch (Exception e) {

this.lastError = whoAmI + ": COM ActiveX exception. " +
e.ToString();
this.Logger.PostMessage(this.LastError,
SyslogMessageSeverity.SLOG_WARNING, whoAmI);
rv = false;

} finally {

// -- Tidy up. --
if (activityInstance != null) {
try {
while (Marshal.ReleaseComObject(activityInstance) > 0) {
// -- Do nothing --
}
} catch (Exception marshalE) {
this.Logger.PostMessage("ReleaseComObject failed : " +
marshalE.ToString(),
SyslogMessageSeverity.SLOG_WARNING, whoAmI);
} // try/catch...
} // if (activityInstance...

activityArguments = null;
activityInstance = null;
activityType = null;

System.GC.Collect();

} // try/catch...

return rv;

} // public bool COMRunActiveXDll...

---------------------------------------------
 
G

Gemma M

This is a nice theory.

However, the problem occurs only after the COM object has been called
several (>1000) times (which makes it a difficult thing to trap in a
debugger!). It happens more quickly if I have several instances of the .NET
application running concurrently.

Also, each instance of the COM object runs in isolation. That is, it uses
the arguments passed to it, but it doesn't depend upon resourse allocated or
otherwise, from previous instances of the COM object.

Therefore, if it were a bug in the COM object, would it not fall over every
time? It looks to me like a resource in one environment or the other (.NET,
COM, Windows) is becoming fragmented and/or exhausted by repeated
instantiations of COM objects from .NET. However, I cannot find in
documentation an event, or a system-call, beyond "while
(Marshal.ReleaseComObject(activityInstance) > 0)" that will tidy up after
each execution of COM.

Gem

Demon News said:
I've found that this is generated not by your code but by the COM object
that you're refering to. It is probably a single scenario that's trying to
do something in the COM object you're calling and the COM object is
falling over. Hopefully, if you examine the inner exception, or if you can
reproduce the problem and debug the other COM object you should be able to
pinpoint the problem.


Gemma M said:
Hi,

I have a C# program (code fragment below), which runs forever, processing
incoming jobs. Part of this program launches a COM object. However,
after
a while I get :

System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x80010007): Automation
error

Does anyone know what can be causing this problem?

Is there other house-keeping, garbage collection, and/or memory
management things I can do to prevent what I'm assuming to be exhaustion
of resources?

I am running Framework 1.1.4322 SP 1.

I load the COM object using :
// -- Create the COM Active X DLL. --
activityType = Type.GetTypeFromProgID(act.ModuleName);
activityInstance = Activator.CreateInstance(activityType);

I unload the COM object using :
while (Marshal.ReleaseComObject(activityInstance) > 0) {

Thanks in advance
G

--------------------------------------------- Code Fragment.---------
Actvivity (the argument for this method) is an object containing text
fields.

// --------------------------------------------------------------------
/// <summary>
/// Given the name of a registered COM ActiveX DLL, this method
/// loads it and attempts to run the action therein.
/// </summary>
/// <param name="activeXName"></param>
/// <returns></returns>
// --------------------------------------------------------------------
public bool COMRunActiveXDll(Activity act) {

bool rv = false; // Return value.
string whoAmI =
Service.IN_WHAT + "COMRunActiveXDLL" + this.currentInstance;

// - The .NET type equivalent to the named COM DLL. -
Type activityType = null;

// - Instance of COM DLL. -
object activityInstance = null;

// - Arguments for the call to the method within the COM DLL. -
object[]activityArguments = null;

// - LastError property of active X dll. -
string activityError = "";

try {

if (act != null) {

// -- Create the COM Active X DLL. --
activityType = Type.GetTypeFromProgID(act.ModuleName);
activityInstance = Activator.CreateInstance(activityType);

// -- Now create the list or arguments for the activity. --
activityArguments = new object[] {act.CaseId, act.StateId,
act.Argument};

// -- Run the activity. --
rv = (bool) activityType.InvokeMember("Action",
BindingFlags.InvokeMethod, null,
activityInstance, activityArguments);

if (rv == false) {

activityError = (string)
activityType.InvokeMember("LastError",
BindingFlags.GetProperty, null, activityInstance,
null);
this.lastError = whoAmI + ": COM ActiveX failed. " +
activityError;
this.Logger.PostMessage(this.LastError,
SyslogMessageSeverity.SLOG_WARNING, whoAmI);

} // if (rv...

} // if (act...

} catch (Exception e) {

this.lastError = whoAmI + ": COM ActiveX exception. " +
e.ToString();
this.Logger.PostMessage(this.LastError,
SyslogMessageSeverity.SLOG_WARNING, whoAmI);
rv = false;

} finally {

// -- Tidy up. --
if (activityInstance != null) {
try {
while (Marshal.ReleaseComObject(activityInstance) > 0) {
// -- Do nothing --
}
} catch (Exception marshalE) {
this.Logger.PostMessage("ReleaseComObject failed : " +
marshalE.ToString(),
SyslogMessageSeverity.SLOG_WARNING, whoAmI);
} // try/catch...
} // if (activityInstance...

activityArguments = null;
activityInstance = null;
activityType = null;

System.GC.Collect();

} // try/catch...

return rv;

} // public bool COMRunActiveXDll...
 
G

Gemma M

I should also add that the .NET application which makes the repeated calls
to COM objects is a replacement of a COM equivalent, which is known to run
"lights-out" for weeks without throwing any exceptions.

G
Demon News said:
I've found that this is generated not by your code but by the COM object
that you're refering to. It is probably a single scenario that's trying to
do something in the COM object you're calling and the COM object is
falling over. Hopefully, if you examine the inner exception, or if you can
reproduce the problem and debug the other COM object you should be able to
pinpoint the problem.


Gemma M said:
Hi,

I have a C# program (code fragment below), which runs forever, processing
incoming jobs. Part of this program launches a COM object. However,
after
a while I get :

System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x80010007): Automation
error

Does anyone know what can be causing this problem?

Is there other house-keeping, garbage collection, and/or memory
management things I can do to prevent what I'm assuming to be exhaustion
of resources?

I am running Framework 1.1.4322 SP 1.

I load the COM object using :
// -- Create the COM Active X DLL. --
activityType = Type.GetTypeFromProgID(act.ModuleName);
activityInstance = Activator.CreateInstance(activityType);

I unload the COM object using :
while (Marshal.ReleaseComObject(activityInstance) > 0) {

Thanks in advance
G

--------------------------------------------- Code Fragment.---------
Actvivity (the argument for this method) is an object containing text
fields.

// --------------------------------------------------------------------
/// <summary>
/// Given the name of a registered COM ActiveX DLL, this method
/// loads it and attempts to run the action therein.
/// </summary>
/// <param name="activeXName"></param>
/// <returns></returns>
// --------------------------------------------------------------------
public bool COMRunActiveXDll(Activity act) {

bool rv = false; // Return value.
string whoAmI =
Service.IN_WHAT + "COMRunActiveXDLL" + this.currentInstance;

// - The .NET type equivalent to the named COM DLL. -
Type activityType = null;

// - Instance of COM DLL. -
object activityInstance = null;

// - Arguments for the call to the method within the COM DLL. -
object[]activityArguments = null;

// - LastError property of active X dll. -
string activityError = "";

try {

if (act != null) {

// -- Create the COM Active X DLL. --
activityType = Type.GetTypeFromProgID(act.ModuleName);
activityInstance = Activator.CreateInstance(activityType);

// -- Now create the list or arguments for the activity. --
activityArguments = new object[] {act.CaseId, act.StateId,
act.Argument};

// -- Run the activity. --
rv = (bool) activityType.InvokeMember("Action",
BindingFlags.InvokeMethod, null,
activityInstance, activityArguments);

if (rv == false) {

activityError = (string)
activityType.InvokeMember("LastError",
BindingFlags.GetProperty, null, activityInstance,
null);
this.lastError = whoAmI + ": COM ActiveX failed. " +
activityError;
this.Logger.PostMessage(this.LastError,
SyslogMessageSeverity.SLOG_WARNING, whoAmI);

} // if (rv...

} // if (act...

} catch (Exception e) {

this.lastError = whoAmI + ": COM ActiveX exception. " +
e.ToString();
this.Logger.PostMessage(this.LastError,
SyslogMessageSeverity.SLOG_WARNING, whoAmI);
rv = false;

} finally {

// -- Tidy up. --
if (activityInstance != null) {
try {
while (Marshal.ReleaseComObject(activityInstance) > 0) {
// -- Do nothing --
}
} catch (Exception marshalE) {
this.Logger.PostMessage("ReleaseComObject failed : " +
marshalE.ToString(),
SyslogMessageSeverity.SLOG_WARNING, whoAmI);
} // try/catch...
} // if (activityInstance...

activityArguments = null;
activityInstance = null;
activityType = null;

System.GC.Collect();

} // try/catch...

return rv;

} // public bool COMRunActiveXDll...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top