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?