473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 7250
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: LEBRUN Thomas | last post by:
Hello :) I would like to use Outlook 2003 in my application so for that, i've added the referece to Outlook 11.0 Object Model to my project. Then, I try this simple code : using System;...
0
by: W Akthar | last post by:
Hi All, I have created a simple Windows Service which needs to be able to send appointments to Outlook. I have no problem makeing a reference to Microsoft Outlook 11.0 Object Library and...
3
by: W Akthar | last post by:
Hi I am trying to create a windows service which queries SQL Server on timed intervals and depending on the results send appointments to Outlook. The problem lies when I try to create an...
4
by: bbdobuddy | last post by:
Hi, How do I open a Microsoft Access 2003 form from Visual Basic.net Thanks in advance bbdobuddy
0
by: Mads Westen | last post by:
Hi, I'm trying to code a application that can create a new email in Outlook I have coded my project in VS 2003, but now I have upgraded to VS 2005. I can not build my project anymore, I get a...
12
by: JC | last post by:
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...
1
by: Marc | last post by:
Hello, Am getting acquainted with VSTO and Visual Studio. I have been really successful adding references to the PIAs for Word, Outlook, Excel, etc. to Console applications and VB applications....
1
by: mary mathews | last post by:
Hi, I'm getting an exception while tried to retrive an outlook contact using asp.net in a console application. The exception is as follows: An unhandled exception of type...
3
OuTCasT
by: OuTCasT | last post by:
Hi I have created an asp.net project that exports items from datagridview to and outlook calendar This is the code that i have used.. Dim body As String Dim ends As String ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.