Alguien sabe porque explota el código siguiente. Al parecer esta asociado a
la labor del Garbage Collector ???? Como lo soluciono?
Uso directivas del compilador para q el GC respete el objeto?
En un caso de prueba donde el folder seleccionado tiene 350 contactos, se
ejecuta hasta el contacto 86 y ahí explota. El error es
Microsoft.Office.Interop.Outlook._Application olApp = new
Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook._NameSpace olNs =
olApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook._Folders oFolders =
olNs.Folders;
Microsoft.Office.Interop.Outlook.MAPIFolder aContacts =
olNs.PickFolder();
Microsoft.Office.Interop.Outlook.Items oItems = aContacts.Items;
for (int i = 0; i <= x; oItems.Count)
{
//Explota en la proxima linea luego de pasar por aqui unas 85 veces. No
tengo condiciones para testear en otros casos de
//prueba si este numero cambia. Supongo q sip.
Microsoft.Office.Interop.Outlook._ContactItem oContact =
(Microsoft.Office.Interop.Outlook._ContactItem)oItems[i];
//Do something with oContact
oContact = null;
}
Este Segundo caso da un error "Array index out of bounds" desde la primera
iteracion.
Microsoft.Office.Interop.Outlook._Application olApp = new
Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook._NameSpace olNs =
olApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook._Folders oFolders =
olNs.Folders;
Microsoft.Office.Interop.Outlook.MAPIFolder aContacts =
olNs.PickFolder();
Microsoft.Office.Interop.Outlook.Items oItems = aContacts.Items;
int x = oItems.Count;
//Explota en la proxima linea.
for (int i = 0; i <= x; i++)
{
Microsoft.Office.Interop.Outlook._ContactItem oContact =
(Microsoft.Office.Interop.Outlook._ContactItem)oItems[i];
//Do something with oContact
oContact = null;
}
Leer las respuestas