Opening email from a share breaks add-in

A

Andrew

Hello Folks,

I have a 2007 Outlook add-in developed in VB.Net which throws the following
error, when an email is attempted to be opened from a share: "Cannot open
file: "file name and path here." The file may not exist, you may not have
permission to open it, or it may be open in another program. Right-click the
folder that contains the file, and then click Properties to check your
permissions for the folder."

The weird thing is sometimes it opens, but most times it doesn't and throws
that error. The code is written to handle the "NewInspector" event which
should run when the email is opened. In the times, the error is throw, the
event is not being hit at all. When it hits the event, everything works fine.

Therefore, it seems like its blowing up trying to hit the event.

Any ideas anyone?

Regards,
 
K

Ken Slovak - [MVP - Outlook]

What type of share is this? Is this a MSG file stored in the file system
somewhere, or what?

Does the exception get thrown when the email is opened using code or by the
user or both?

Is that the complete exception you get? Are you doing exception logging and
does this trigger that? Are you handling unhandled exceptions, and if so
does that exception trap fire at all?
 
A

Andrew

Hey,

Its actually a mapped drive and its an MSG file.

The exception is thrown in both instances.

Yes, that's everything that's thrown when it errors. There is exception
logging, but nothing's being caught by the code. Went through the event log
and there doesn't seem to be anything related there.

As another test, I removed the "application.NewInspector" event and it never
broke, so it seems to be breaking trying to hit the event.
 
T

Tom

I have had similar problems when running from the debugger and and not as an
adminstrator. Be careful on Vista

Simple test ...try this on XP and see if you get the same error.
 
T

Tom

The only thing I can think of is to start commenting code out until the
condition go's away.
 
K

Ken Slovak - [MVP - Outlook]

Does this error fire in both run mode and debug mode?

What is your exact code in the NewInspector() event handler?

How is the item being opened, from code or by the user in the UI?
 
A

Andrew

Hey,

It fires in every case, Run Mode, Debug mode and when deployed to a machine.
It opens once and then is broken after that.

The email is being opened from a Windows Explorer browser by the user,
double-clicking it.

Here's the initial part of the code that traps the event:

global variable
Dim WithEvents m_olInspectors As Outlook.Inspectors
InspectorWrapper is a custom class

Private Sub m_olInspectors_NewInspector(ByVal Inspector As
Microsoft.Office.Interop.Outlook.Inspector) Handles
m_olInspectors.NewInspector
Dim inspectorWrapper As InspectorWrapper = Nothing
Dim oMailItemTest As Outlook.MailItem = Nothing

Try
......
Catch ex As SystemException
MessageBox.Show(ex.Message)
WriteLog("clsOutlookAddIn.vb Line 217: New Inspector event handler failed to
run: " & ex.Message)
Finally
inspectorWrapper = Nothing
oMailItemTest = Nothing
End Try
End Sub

Regards,
 
K

Ken Slovak - [MVP - Outlook]

OK, I did some testing on this and from what I found here it appears that
accessing Inspector.CurrentItem directly or indirectly at all without later
fully releasing that object will cause this error.

For example, assuming your NewInspector() code has just this line in it:

If (TypeOf(Inspector.CurrentItem) Is Outlook.MailItem) Then

That will cause this error.

So will this line:

Dim currentOLItem As Object = Inspector.CurrentItem

However, if you use these lines the problem seems to go away:

Dim currentOLItem As Object = Inspector.CurrentItem
If (TypeOf(currentOLItem) Is Outlook.MailItem) Then
' whatever code you want
End If

Marshal.ReleaseComObject(currentOLItem)
currentOLItem = Nothing

I haven't seen the problem when opening Outlook items within Outlook, it
seems to occur for MSG items however, no matter where they're stored. A
network share or whatever is not required to cause the problem.

See if explicitly instantiating an object for Inspector.CurrentItem so you
have control over it, and then fully releasing it solves the problem for
you. Please post back on your results, if you still have the problem I'll
take it up with the Outlook team.
 
K

Ken Slovak - [MVP - Outlook]

It's also been bugged to the Outlook team, with a repro found (even in VBA),
and it's being investigated.
 
A

Andrew

I'm posting the entire block to show the code that's being used. I'm going to
test what you mentioned to see what happens. Will post back in a couple
minutes.


Private Sub m_olInspectors_NewInspector(ByVal Inspector As
Microsoft.Office.Interop.Outlook.Inspector) Handles
m_olInspectors.NewInspector
Dim inspectorWrapper As InspectorWrapper = Nothing
Dim oMailItemTest As Outlook.MailItem = Nothing
Dim strLoginFailed As String = ""
Try
If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then

oMailItemTest = CType(Inspector.CurrentItem, Outlook.MailItem)

'Determine if a New Mail is being composed
If IsNothing(oMailItemTest.EntryID) Then
inspectorWrapper = New InspectorWrapper(Inspector,
inspectorID, False)
'Uses the inspector key to reference the wrapper object
in the collection when added
InspectorList.Add(inspectorWrapper,
CStr(inspectorWrapper.Key), True)
'Increment to give each wrapper object a unique ID
inspectorID += 1
Else
'Web Service call to get client modules
If IsNothing(g_sXMLModules) Then
g_sXMLModules = New XmlDocument
If (g_blnSuccess) Then

g_sXMLModules.LoadXml(WebServiceProxy.GetDashboardModules(g_sToken,
"Outlook"))
Else
AutoLoginClick(True)
WriteLog("clsOutlookAddIn.vb LIne 190: Automatic
logging successfully completed when attempting to load Outlook Modules when
the Modules XML is Nothing!")
If (g_blnSuccess) Then

g_sXMLModules.LoadXml(WebServiceProxy.GetDashboardModules(g_sToken,
"Outlook"))
End If
End If
Else
If
IsNothing(g_sXMLModules.SelectSingleNode("DashboardList/Dashboard")) Then
If (g_blnSuccess) Then

g_sXMLModules.LoadXml(WebServiceProxy.GetDashboardModules(g_sToken,
"Outlook"))
Else
AutoLoginClick(True)
WriteLog("Automatic logging successfully
completed when attempting to load Outlook Modules when the webservice
populates the Modules XML!")

If (g_blnSuccess) Then

g_sXMLModules.LoadXml(WebServiceProxy.GetDashboardModules(g_sToken,
"Outlook"))
End If
End If
End If
End If

inspectorWrapper = New InspectorWrapper(Inspector,
inspectorID, True)
InspectorList.Add(inspectorWrapper,
CStr(inspectorWrapper.Key), False)
inspectorID += 1
End If
End If
Catch ex As SystemException
MessageBox.Show(ex.Message)
WriteLog("clsOutlookAddIn.vb Line 217: New Inspector event
handler failed to run: " & ex.Message)
Finally
inspectorWrapper = Nothing
oMailItemTest = Nothing
Inspector = Nothing
End Try
End Sub
 
K

Ken Slovak - [MVP - Outlook]

Make sure to fully release any local COM objects you create in that event
handler, don't do that with any class/module/global level COM objects.
 
A

Andrew

Thanks a lot Ken, that fixed the problem!

Ken Slovak - said:
Make sure to fully release any local COM objects you create in that event
handler, don't do that with any class/module/global level COM objects.
 
K

Ken Slovak - [MVP - Outlook]

Excellent.

At least we have a workaround now until this ends up getting fixed, either
in SP3 or in a hotfix QFE.
 

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