Outlook Automation Problem using Microsoft.Office.Interop.Outlook

D

DP

Receiving message in Outlook when call interop from vb.net and trying to
read/load emails from inbox to windows form into datagridview.

Message is: The add-in "c\program files\postx\trusted messaging client for
outlook\..." could not be installed or loaded.

This message occurs at different times, never on the same email. Usually
after it loads over 150 emails. We think it is related to COM performance,
thus put in System.Threading.Thread.Sleep(100), this seems to work, but slow
to load emails.

Any input would be helpful. Here is the basic code.

Dim oAppm As Microsoft.Office.Interop.Outlook.Application = New
Microsoft.Office.Interop.Outlook.Application
Dim oInboxm As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim oItemsm As Microsoft.Office.Interop.Outlook.Items
Dim oNSm As Microsoft.Office.Interop.Outlook.NameSpace =
oAppm.GetNamespace("MAPI")

oInboxm =
oNSm.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)

oItemsm = oInboxm.Items

For i As Integer = oItemsm.Count To 1 Step -1
'Test to make sure item is a mail item and not a meeting request.
sClassComp = oItemsm.Item(i).messageclass
Select Case sClassComp
Case "IPM.Note",
"IPM.Note.Rules.ReplyTemplate.Microsoft", "IPM.Note.Secure"

Me.DataGridView1.Rows.Add()

Dim oMsgm As Microsoft.Office.Interop.Outlook.MailItem
oMsgm = TryCast(oItemsm.Item(i), Microsoft.Office.Interop.Outlook.MailItem)

iCellCounter = 0

Me.DataGridView1.Rows(iRowCounter).Cells(iCellCounter).Value =
oMsgm.SenderName
Me.DataGridView1.Rows(iRowCounter).Cells(iCellCounter + 1).Value =
oMsgm.Subject
Me.DataGridView1.Rows(iRowCounter).Cells(iCellCounter + 2).Value =
oMsgm.ReceivedTime
Me.DataGridView1.Rows(iRowCounter).Cells(iCellCounter + 3).Value =
oMsgm.ConversationIndex

Pause()

iRowCounter += 1
Case Else
End Select
Next i
 
K

Ken Slovak - [MVP - Outlook]

That error is a startup load error for a COM addin. The only way to tell
what's failing in the load is to do managed code troubleshooting and look at
the Fusion logs. See
http://blogs.msdn.com/vsod/archive/2008/04/22/Troubleshooting-com-add-in-load-failures.aspx
for information on that.

Usually if you run out of RPC channels it's against Exchange server, and it
usually happens at around 250 passes in a loop. That's due to managed code
not releasing objects in the garbage collector soon enough, your pause may
help by allowing the GC to run. A better approach is to explicitly release
all of your objects by setting them to Nothing, and you may even have to
call Marshal.ReleaseComObject() on them and then call to GC.Collect() each
pass in the loop.

Also, never use compound dot operators such as this:

sClassComp = oItemsm.Item(i).messageclass

That creates an internal object for the oItemsm.Item(i) object that can't be
explicitly released. Use instead something like this:

Dim item As object = oItemsm.Item(i)
sClassComp = item.MessageClass

That allows you to explicitly release "item".

However, the error when you run into a limit on RPC channels is usually a
lack of resources or memory error, not a load error.

Another thing is if this code is running in an Outlook COM addin never, ever
use New to create an Outlook.Application object. Instead, use the
Application object passed to you in Startup() for VSTO addins or in
OnConnection() in shared addins.
 
V

Vincent Masavah

Thanks this code has helped but i want to open the mail from my datagrid. how will i do that.

Thanks
masavah
Receiving message in Outlook when call interop from vb.net and trying to
read/load emails from inbox to windows form into datagridview.

Message is: The add-in "c\program files\postx\trusted messaging client for
outlook\..." could not be installed or loaded.

This message occurs at different times, never on the same email. Usually
after it loads over 150 emails. We think it is related to COM performance,
thus put in System.Threading.Thread.Sleep(100), this seems to work, but slow
to load emails.

Any input would be helpful. Here is the basic code.

Dim oAppm As Microsoft.Office.Interop.Outlook.Application = New
Microsoft.Office.Interop.Outlook.Application
Dim oInboxm As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim oItemsm As Microsoft.Office.Interop.Outlook.Items
Dim oNSm As Microsoft.Office.Interop.Outlook.NameSpace =
oAppm.GetNamespace("MAPI")

oInboxm =
oNSm.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)

oItemsm = oInboxm.Items

For i As Integer = oItemsm.Count To 1 Step -1
'Test to make sure item is a mail item and not a meeting request.
sClassComp = oItemsm.Item(i).messageclass
Select Case sClassComp
Case "IPM.Note",
"IPM.Note.Rules.ReplyTemplate.Microsoft", "IPM.Note.Secure"

Me.DataGridView1.Rows.Add()

Dim oMsgm As Microsoft.Office.Interop.Outlook.MailItem
oMsgm = TryCast(oItemsm.Item(i), Microsoft.Office.Interop.Outlook.MailItem)

iCellCounter = 0

Me.DataGridView1.Rows(iRowCounter).Cells(iCellCounter).Value =
oMsgm.SenderName
Me.DataGridView1.Rows(iRowCounter).Cells(iCellCounter + 1).Value =
oMsgm.Subject
Me.DataGridView1.Rows(iRowCounter).Cells(iCellCounter + 2).Value =
oMsgm.ReceivedTime
Me.DataGridView1.Rows(iRowCounter).Cells(iCellCounter + 3).Value =
oMsgm.ConversationIndex

Pause()

iRowCounter += 1
Case Else
End Select
Next i
On Tuesday, February 10, 2009 10:49 AM Ken Slovak - [MVP - Outlook] wrote:
That error is a startup load error for a COM addin. The only way to tell
what's failing in the load is to do managed code troubleshooting and look at
the Fusion logs. See
http://blogs.msdn.com/vsod/archive/2008/04/22/Troubleshooting-com-add-in-load-failures.aspx
for information on that.

Usually if you run out of RPC channels it's against Exchange server, and it
usually happens at around 250 passes in a loop. That's due to managed code
not releasing objects in the garbage collector soon enough, your pause may
help by allowing the GC to run. A better approach is to explicitly release
all of your objects by setting them to Nothing, and you may even have to
call Marshal.ReleaseComObject() on them and then call to GC.Collect() each
pass in the loop.

Also, never use compound dot operators such as this:

sClassComp = oItemsm.Item(i).messageclass

That creates an internal object for the oItemsm.Item(i) object that can't be
explicitly released. Use instead something like this:

Dim item As object = oItemsm.Item(i)
sClassComp = item.MessageClass

That allows you to explicitly release "item".

However, the error when you run into a limit on RPC channels is usually a
lack of resources or memory error, not a load error.

Another thing is if this code is running in an Outlook COM addin never, ever
use New to create an Outlook.Application object. Instead, use the
Application object passed to you in Startup() for VSTO addins or in
OnConnection() in shared addins.





news:[email protected]...
Submitted via EggHeadCafe - Software Developer Portal of Choice
SharePoint WorkFlow Basics
http://www.eggheadcafe.com/tutorial...-356f75d9fca9/sharepoint-workflow-basics.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top