Outlook COMException

System.Runtime.InteropServices.COMException .. Your server administrator has limited the number of items that you can open at the same time ...

at Microsoft.Office.Interop.Outlook._AppointmentItem.get_UserProperties ()

var calendar = outlookApplication.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderCalendar); if (calendar == null || calendar.Items == null) { return null; } var calendarItems = calendar.Items; if (calendarItems != null && calendarItems.Count > 0) { // Dont convert to LINQ or foreach please -> may cause Outlook memory leaks. for (int counter = 1; counter <= calendarItems.Count; counter++) { var appointment = calendarItems[counter] as AppointmentItem; if (appointment != null) { var userProperty = appointment.UserProperties.Find("myInformation"); if (userProperty != null && userProperty.Value == myValue) { return appointment ; } } } } 

Maybe its purpose .UserProperties.Find ("myInformation") raises a COMException?

+4
source share
3 answers

I found a solution for this. No need to use Find cause Restrict to do what I need.

 ... string filter = string.Format("[myInformation] = '{0}'", myInformation); var calendarItems = calendar.Items.Restrict(filter); ... 
+1
source

When you're done closing Outlook Mailitem, release it.

 For Each item As Outlook.MailItem In oFolder.Items '<process item code> 'Close the item 'SaveMode Values 'olDiscard = 1 'olPromptForSave = 2 'olSave = 0 item.Close(1) 'Release item Marshal.ReleaseComObject(item) Next 
+3
source

You need to make sure that you release the Outlook items as soon as you finish using them using Marshal.ReleaseComObject (), rather than waiting for the garbage collector to start working.

You also need to avoid multipoint notation to make sure you are not getting implicit variables (created by the compiler) that contain these intermediate results and cannot be explicitly specified and released.

+2
source

Source: https://habr.com/ru/post/1444598/


All Articles