views:

238

answers:

2

I thought I had a working solution for converting .mdi files to PDF using the Microsoft Office Document Imaging object model. The solution is in a Windows Service, but now I'm running into some errors that I'm having trouble tracking down info on.

The exception I get is:

The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)) System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
at MODI.DocumentClass.Create(String FileOpen) at DocumentStore.Mdi2PDF(String path, String newPath)

Then, in the Event Viewer there is the following Application error:

Faulting application MyWindowsServiceName.exe, version 1.0.0.0, time stamp 0x4b97f185, faulting module mso.dll, version 12.0.6425.1000, time stamp 0x49d65443, exception code 0xc0000005, fault offset 0x0000bd8e, process id 0xa5c, application start time 0x01cac08cf032914b.

Here's the method that is doing the conversion:

private int? Mdi2PDF(String path, String newPath)
{
    int? pageCount = null;
    string tmpTif = Path.GetTempFileName();

    MODI.Document mdiDoc = new MODI.Document();
    mdiDoc.Create(path);
    mdiDoc.SaveAs(tmpTif,
        MODI.MiFILE_FORMAT.miFILE_FORMAT_TIFF_LOSSLESS,
        MODI.MiCOMP_LEVEL.miCOMP_LEVEL_HIGH);
    mdiDoc.Close(false);

    pageCount = Tiff2PDF(tmpTif, newPath);
    if (File.Exists(tmpTif))
        File.Delete(tmpTif);

    return pageCount;
}

I removed all threading from the service invoking this, so that only the primary thread was initializing the MODI object, but still got the error, so it doesn't appear to be threading related.

I also built a a console apps converting hundreds of documents and DID NOT get the exception.

So, it seems to be caused by creating too many instances of the MODI object, but only instantiated within a Service? Doesn't quite make sense.

Anybody have any clues about these errors and how to debug them further?

+1  A: 

It crashed. It's a dead parrot. An AccessViolation hardware exception, in an Office DLL (mso.dll). You have few options to figure out why exactly it crashed, this is not your code. But using threading is definitely a good way to crash a COM server that's single-threaded. Any kind of Office code would qualify. Get rid of the threading first, then call Microsoft Support.

Hans Passant
Thanks, I agree, it's a good idea to get rid of the threading to further isolate any issues. I've also been trying to treat the MODI.Document instance as a singleton and just call the close() and create() rather than creating a new instance every time.
RyanW
+1  A: 

There's something interesting here about closing the COMObject after its use or something like that. This might perhaps help, I hope it does.

  1. COMException 0x80010105
  2. Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))

It seems to have something related to disposing objects, either an object disposed too early, or not disposed at all.

Have your ever tried to call the Garbage Collector once in a while throughout your callings to the COM object methods?

I don't know, I'm throwing up everything that gets to my mind, perhaps will it make it end as a solution somewhere! =)

Will Marcouiller
Thanks, yeah, I agree, I think I've narrowed it down a problem with disposing the objects, and I appreciate the suggestions.I built a console app that I ran 2 versions simultaneously, creating and closing a couple hundred MDI objects and no problem. But, when I get it into a Service, then the problem comes back. For now, I'm just going to create a single instance of the MODI object and call the create(), saveas() and close() on it. That seems to have stabilized it. I'll experiment some more with invoking the garbage collector too.
RyanW