473,722 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem whith C# Microsoft.Offic e.Interop.Outlo ok 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.Offic e.Interop.Outlo ok._Application olApp = new
Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass();
Microsoft.Offic e.Interop.Outlo ok._NameSpace olNs =
olApp.GetNamesp ace("MAPI");
Microsoft.Offic e.Interop.Outlo ok.MAPIFolder aContacts =
olNs.GetDefault Folder(Microsof t.Office.Intero p.Outlook.OlDef aultFolders.olF olderContacts);
Microsoft.Offic e.Interop.Outlo ok.Items oItems = aContacts.Items ;
FAddressBookNam e = aContacts.Addre ssBookName;
foreach (Microsoft.Offi ce.Interop.Outl ook._ContactIte m oContact in
oItems)
{

//do something
}

"JC" <jc***@macomexp ress.comwrote in message
news:uX******** ******@TK2MSFTN GP02.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.Offic e.Interop.Outlo ok._Application olApp = new
Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass();

Microsoft.Offic e.Interop.Outlo ok._NameSpace olNs =
olApp.GetNamesp ace("MAPI");

Microsoft.Offic e.Interop.Outlo ok._Folders oFolders =
olNs.Folders;

Microsoft.Offic e.Interop.Outlo ok.MAPIFolder aContacts =
olNs.PickFolder ();

Microsoft.Offic e.Interop.Outlo ok.Items oItems =
aContacts.Items ;

for (int i = 0; i <= x; oItems.Count)

{ //Explota en la proxima linea.

Microsoft.Offic e.Interop.Outlo ok._ContactItem oContact =
(Microsoft.Offi ce.Interop.Outl ook._ContactIte m)oItems[i];

//Do something with oContact

oContact = null;

}

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

Microsoft.Offic e.Interop.Outlo ok._Application olApp = new
Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass();

Microsoft.Offic e.Interop.Outlo ok._NameSpace olNs =
olApp.GetNamesp ace("MAPI");

Microsoft.Offic e.Interop.Outlo ok._Folders oFolders =
olNs.Folders;

Microsoft.Offic e.Interop.Outlo ok.MAPIFolder aContacts =
olNs.PickFolder ();

Microsoft.Offic e.Interop.Outlo ok.Items oItems =
aContacts.Items ;

int x = oItems.Count;

//Explota en la proxima linea.

for (int i = 0; i <= x; i++)

{

Microsoft.Offic e.Interop.Outlo ok._ContactItem oContact =
(Microsoft.Offi ce.Interop.Outl ook._ContactIte m)oItems[i];

//Do something with oContact

oContact = null;

}

Nov 15 '06 #1
2 7302
If you think the problem is the Garbage Collector is not collecting
memory that is free, you can programmaticall y 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.Offic e.Interop.Outlo ok._Application olApp = new
Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass();
Microsoft.Offic e.Interop.Outlo ok._NameSpace olNs =
olApp.GetNamesp ace("MAPI");
Microsoft.Offic e.Interop.Outlo ok.MAPIFolder aContacts =
olNs.GetDefault Folder(Microsof t.Office.Intero p.Outlook.OlDef aultFolders.olF olderContacts);
Microsoft.Offic e.Interop.Outlo ok.Items oItems = aContacts.Items ;
FAddressBookNam e = aContacts.Addre ssBookName;
foreach (Microsoft.Offi ce.Interop.Outl ook._ContactIte m oContact in
oItems)
{

//do something
}

"JC" <jc***@macomexp ress.comwrote in message
news:uX******** ******@TK2MSFTN GP02.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.Offic e.Interop.Outlo ok._Application olApp = new
Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass();

Microsoft.Offic e.Interop.Outlo ok._NameSpace olNs =
olApp.GetNamesp ace("MAPI");

Microsoft.Offic e.Interop.Outlo ok._Folders oFolders =
olNs.Folders;

Microsoft.Offic e.Interop.Outlo ok.MAPIFolder aContacts =
olNs.PickFolder ();

Microsoft.Offic e.Interop.Outlo ok.Items oItems =
aContacts.Items ;

for (int i = 0; i <= x; oItems.Count)

{ //Explota en la proxima linea.

Microsoft.Offic e.Interop.Outlo ok._ContactItem oContact =
(Microsoft.Offi ce.Interop.Outl ook._ContactIte m)oItems[i];

//Do something with oContact

oContact = null;

}

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

Microsoft.Offic e.Interop.Outlo ok._Application olApp = new
Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass();

Microsoft.Offic e.Interop.Outlo ok._NameSpace olNs =
olApp.GetNamesp ace("MAPI");

Microsoft.Offic e.Interop.Outlo ok._Folders oFolders =
olNs.Folders;

Microsoft.Offic e.Interop.Outlo ok.MAPIFolder aContacts =
olNs.PickFolder ();

Microsoft.Offic e.Interop.Outlo ok.Items oItems =
aContacts.Items ;

int x = oItems.Count;

//Explota en la proxima linea.

for (int i = 0; i <= x; i++)

{

Microsoft.Offic e.Interop.Outlo ok._ContactItem oContact =
(Microsoft.Offi ce.Interop.Outl ook._ContactIte m)oItems[i];

//Do something with oContact

oContact = null;

}
Nov 15 '06 #2

"JC" <jc***@macomexp ress.comwrote in message
news:ux******** ******@TK2MSFTN GP02.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.Offic e.Interop.Outlo ok._Application olApp = new
| Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass();
| Microsoft.Offic e.Interop.Outlo ok._NameSpace olNs =
| olApp.GetNamesp ace("MAPI");
| Microsoft.Offic e.Interop.Outlo ok.MAPIFolder aContacts =
|
olNs.GetDefault Folder(Microsof t.Office.Intero p.Outlook.OlDef aultFolders.olF olderContacts);
| Microsoft.Offic e.Interop.Outlo ok.Items oItems = aContacts.Items ;
| FAddressBookNam e = aContacts.Addre ssBookName;
| foreach (Microsoft.Offi ce.Interop.Outl ook._ContactIte m 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
5366
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; using Microsoft.Office.Interop.Outlook;
0
2030
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 compiling the code. the problem arises when I try to install the service using installutil. The error message I get is the following
3
2350
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 outlook application object.
4
12277
by: bbdobuddy | last post by:
Hi, How do I open a Microsoft Access 2003 form from Visual Basic.net Thanks in advance bbdobuddy
0
2021
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 looooooong error. I can also see, when I add a reference to my project, that the Microsoft.Office.Core and the Outlook References have a yellow exclamation mark. If I remove my reference to the Outlook object model, the code marked with a
12
1933
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 is a "Array index out of bounds".
1
4738
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. However, I also wanted to investigate add-ins (specifically for Outlook). I downloaded VBTO 2007 SE and installed it, and now when I start Visual Studio I see project templates for, e.g. Outlook Add-In.
1
2111
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 'System.NullReferenceException' occurred in ConsoleApplication1.exe,Additional information: Object reference not set to an instance of an object .. Can anybody help me pls.... my code is like this..
3
11647
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 Dim location As String Dim start As String Dim subject As String
0
8739
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9157
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.