Adam
Adam

Reputation: 1885

C# COM application crash debugging

The C# console application running .NET 4.5.2 (app1) opens a COM application (app2) and does some work with that app2's API. So far all of the work is successful, but sometimes when app1 attempts to close app2, app2 hangs permanently.

If the process for app2 is ended with task manager then app1 reports access denied. Does that occur because the terminated process is no longer available or does it occur because it was blocking a thread in app1 and it was unable to report the error until the thread was allowed to continue?

The code used to terminate app2 is

    private static void CloseSW(SldWorks swApp, Process sw_proces)
    {
        // Close with API call            
        if (Task.Run(() => { swApp.CloseAllDocuments(true); swApp.ExitApp(); }).Wait(TimeSpan.FromSeconds(20)))
            return;

        // Kill process if API call failed
        if (Task.Run(() => { SWHelper.CloseSW(sw_proces); }).Wait(TimeSpan.FromSeconds(20)))
            return;

        // Unable to close SolidWorks, ignore error and continue      
        // This will eventually cause SolidWorks to crash and the crash handler will take over
    }

This code should never take much more than 40 seconds to complete, but maybe the COM interop is causing some unexpected behaviour?

I am unable to reproduce this error on a development machine. What it the best way to trace the exact point of failure? It is possible that the failure is not in CloseSW but some point before this. Is there a better way to trace the error than to write each line to a log file?

It is also worth noting that this code works for 60 - 150 runs before it has any errors and both applications are closed between each run.

I have control of the remote environment so remote debugging is an option, but I've never set that up before.

Upvotes: 0

Views: 123

Answers (1)

user4573148
user4573148

Reputation:

Typically with COM interops causing issues is that IIS is having issues with the object using the current ISAPI.dll. Please verify that your permissions are configured within your assembly to work with your current version of IIS>

A few questions to help assist would be, which framework version are you using, which version of IIS and what is your Application Pool using for a framework.

HTH

Upvotes: 1

Related Questions