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?
There's something interesting here about closing the COMObject after its use or something like that. This might perhaps help, I hope it does.
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! =)
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.
User contributions licensed under CC BY-SA 3.0