Tuesday, March 1, 2011

Com Object Exception

I wrote an application that loops through a set of records and prints two things.

One is a report from SSRS wich works correctly.

The other is a drawing that uses a COM object to print. The COM object randomly fails and causes the program to quit.

Is there a way to stop it from killing the entire program when the COM Object fails? I have tried catch every exception at every level and it still does not work.

From stackoverflow
  • Are you using the COM object from multiple threads? You should only access the COM object from a single thread with a message pump. In my experience this can cause weird instability which cannot be trapped via a try-catch.

    Stu Mackellar : This only applies if it's an STA (single-threaded apartment) object.
  • It sounds like the issue maybe with the com object itself and not your code. If this is the case then if the com object does not throw an error then you will not be able to catch one.

    Kind Regards

    Tony Smith-Brewster

  • Do you have the code of COM object that you are calling. If you have code then check whether there any exit command on failure.

    Travis : I don't have the code only the documentation and it does not mention any exit commands listed.
    Vinay : Is it COM dll or exe?
    Vinay : If it is a exe then I think, it should not exit on failure. This happens only if it is a dll
    Travis : It is a dll. I found some delegates labeled OnFailedLoadingDocumentEventHandler, OnFailedPrintingDocumentEventHandler, and OnFailedSavingDocumentEventHandler. I may be able to use these to stop the errors.
    Vinay : Whether your application gets the control before exit or it just exists in the dll. If you are getting the control before exist can you check the return value of the call?
    Travis : It has OnFinishedLoading and OnFinishedPrinting methods that I am using to print and dispose with but it does not return a value. The developer states in the documentation that it spawns a new thread to load the document and referencing it before it has finished could cause crashes.
    Vinay : Is input data that is given to dll is causing crash? You can check by creating a sample application which instantiates the dll interfaces and inputs the hard coded values. Is it possible to implement a sample application to do this?
    Travis : During testing it works fine. I cannot find the place the problem is happening. It only happens in production.

0 comments:

Post a Comment