469,342 Members | 5,849 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

problem whith C# Microsoft.Office.Interop.Outlook namespace (null reference)

JC
Anybody knows what problem has this code? I think, in the Garbage
Collector? You know the Solution?
The program in the test's case, whit 350 contacts, run OK before number
86. The error is a "Array index out of bounds".
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.MAPIFolder aContacts =
olNs.GetDefaultFolder(Microsoft.Office.Interop.Out look.OlDefaultFolders.olFolderContacts);
Microsoft.Office.Interop.Outlook.Items oItems = aContacts.Items;
FAddressBookName = aContacts.AddressBookName;
foreach (Microsoft.Office.Interop.Outlook._ContactItem oContact in
oItems)
{

//do something
}

"JC" <jc***@macomexpress.comwrote in message
news:uX**************@TK2MSFTNGP02.phx.gbl...
Hi...

Anybody knows what problem has this code? I think, in the Garbage
Collector? You know the Solution?

The program in the test's case, whit 350 contacts, run OK before number
86. The error is a "Array index out of bounds".

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.

Microsoft.Office.Interop.Outlook._ContactItem oContact =
(Microsoft.Office.Interop.Outlook._ContactItem)oIt ems[i];

//Do something with oContact

oContact = null;

}

In this second case, the error appear in the line before the "for".

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)oIt ems[i];

//Do something with oContact

oContact = null;

}

Nov 15 '06 #1
2 6860
If you think the problem is the Garbage Collector is not collecting
memory that is free, you can programmatically instruct the GC to
collect the garbage with the following line of code.

GC.Collect();

That said, I don't think a problem with the GC would cause the error
message you saw. Can you post what happens in the foreach loop b/c it
seems to me that is where you are overreaching your array size.

JC wrote:
Anybody knows what problem has this code? I think, in the Garbage
Collector? You know the Solution?
The program in the test's case, whit 350 contacts, run OK before number
86. The error is a "Array index out of bounds".
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.MAPIFolder aContacts =
olNs.GetDefaultFolder(Microsoft.Office.Interop.Out look.OlDefaultFolders.olFolderContacts);
Microsoft.Office.Interop.Outlook.Items oItems = aContacts.Items;
FAddressBookName = aContacts.AddressBookName;
foreach (Microsoft.Office.Interop.Outlook._ContactItem oContact in
oItems)
{

//do something
}

"JC" <jc***@macomexpress.comwrote in message
news:uX**************@TK2MSFTNGP02.phx.gbl...
Hi...

Anybody knows what problem has this code? I think, in the Garbage
Collector? You know the Solution?

The program in the test's case, whit 350 contacts, run OK before number
86. The error is a "Array index out of bounds".

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.

Microsoft.Office.Interop.Outlook._ContactItem oContact =
(Microsoft.Office.Interop.Outlook._ContactItem)oIt ems[i];

//Do something with oContact

oContact = null;

}

In this second case, the error appear in the line before the "for".

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)oIt ems[i];

//Do something with oContact

oContact = null;

}
Nov 15 '06 #2

"JC" <jc***@macomexpress.comwrote in message
news:ux**************@TK2MSFTNGP02.phx.gbl...
| Anybody knows what problem has this code? I think, in the Garbage
| Collector? You know the Solution?
| The program in the test's case, whit 350 contacts, run OK before number
| 86. The error is a "Array index out of bounds".
|
|
| 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.MAPIFolder aContacts =
|
olNs.GetDefaultFolder(Microsoft.Office.Interop.Out look.OlDefaultFolders.olFolderContacts);
| Microsoft.Office.Interop.Outlook.Items oItems = aContacts.Items;
| FAddressBookName = aContacts.AddressBookName;
| foreach (Microsoft.Office.Interop.Outlook._ContactItem oContact in
| oItems)
| {
|
| //do something
| }
|
|

Forget about the GC, just run your code through the debugger and watch the
index when it throws. Anyway, the piece of code you post is not the cause,
it's the "do something" which goes wrong

Willy.
Nov 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by LEBRUN Thomas | last post: by
reply views Thread by W Akthar | last post: by
4 posts views Thread by bbdobuddy | last post: by
1 post views Thread by Marc | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.