Search code examples
interoplotus-notescom-interoplotus-dominointerop-domino

IBM Lotus Notes Domino DLL


The Domino interop API which is included with Lotus Notes causes an out of memory exception in .NET when the NotesDXLExporter class based object fails to export the 390th record, which is a big document, after exporting 389 records (which are smaller documents).

Here is a code snippet:

  1. I initialize the NotesDXLExporter class.

    NotesDXLExporter dxl1 = null;

  2. I then configure the NotesDXLExported object as shown below:

    dxl1 = notesSession.CreateDXLExporter(); dxl1.ExitOnFirstFatalError = false; dxl1.ConvertNotesbitmapsToGIF = true; dxl1.OutputDOCTYPE = false;

  3. I then perform a for a loop shown below in reading documents using the dxl1 class (line on which exception occurs is indicated below).

    NotesView vincr = database.GetView(@"(AllIssuesView)"); //view from an NSF file for (int i = 1; i < vincr.EntryCount; i++) { try {

                    vincrdoc = vincr.GetNthDocument(i);
    
    
                        System.IO.File.WriteAllText(@"C:\Temp\" + i + @".txt", dxl1.Export(vincrdoc)); //OUT OF MEMORY EXCEPTION HAPPENS HERE WHEN READING A BIG DOCUMENT.
    
    
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex);
                }
    

I have tried using a different version of the Interop domino dll and had had no success.

As I understand this, I see an API issue but I dont know if I am missing something?

Can you please shed some light on this?

Thanks in advance.

Subbu


Solution

  • You haven't said what version of the Lotus Notes you are working with. Given the history of DXL, I would say that you should try your code on the latest version of Notes that you possibly can.

    But also, I don't see any calls to recycle(). Failure to call recycle() for Domino objects causes memory to leak from the Domino back end classes, and since you are running out of memory it could be contributing to your problem. You should also not use a for loop and getNthDocument. You should use getFirstDocument and a while loop with getNextDocument. You'll get much better performance. Putting these two things together leads you to the common pattern of using a temporary document to hold the result of getNextDocument, allowing you to recycle the current document, and then assign the temp document to the current, which would be something like this (not error-checked!)

    NotesView vincr = database.GetView(@"(AllIssuesView)"); //view from an NSF file 
    vincrdoc = vincr.getFirstDocument();
    while (vincrdoc != null)
    { 
       try {
           System.IO.File.WriteAllText(@"C:\Temp\" + i + @".txt", dxl1.Export(vincrdoc));     
       }
       catch(Exception ex)
       {
           Console.WriteLine(ex);
       }
       Document nextDoc = vincr.getNextDocument(vincrdoc);
       vincrdoc.recycle();
       vincrdoc = nextDoc;
    
    }