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...
---------------------------------------------
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...
---------------------------------------------