I am having issues iterating through the Attachments collection of an RDOMail object. If I open an external MSG file using GetMessageFromMsgFile and attempt to iterate through the attachments a second time I receive an E_ACCESSDENIED exception. I have tried accessing the attachments using For Each, GetEnumerator and the Item property. In all of these scenarios, the first time I access an attachment it works, but any subsequent attempts fail with the Access Denied error.
************** Exception Text **************
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Runtime.InteropServices.CustomMarshalers.EnumeratorViewOfEnumVariant.MoveNext()
I have tried the same code on the same message but opened directly from the Inbox, and it works as expected and I can iterate the attachments multiple times.
The issue seems related to VB.NET assemblies, as I can iterate the Attachments of an external MSG file multiple times if I use the same code in VBA in Excel for example.
The trouble is, I need to process lots of external MSG files on the file system, with the ability to interrogate the attachments a number of times from a VB.NET assembly.
I am in the process of evaluating Redemption, before purchasing.
Yes, the messages created on top of MSG files won't let you access attachments or attachment table objects again until the first instance of the corresponding object is released.
Make sure you avoid using multiple dot notation (to avoid implicit variables) and release all Redemption objects as soon as you are done with them using
Marshal.ReleaseComObject(). You might also want to call
GC.Collect() after processing the file to release all pending objects in case there are still hanging references.
User contributions licensed under CC BY-SA 3.0