none
Outlook Marshall Error RRS feed

  • Question

  • I am getting this error

    System.Runtime.InteropServices.COMException (0x9494010F): Exception from HRESULT: 0x9494010F

    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)

    at System.Runtime.InteropServices.CustomMarshalers.EnumeratorViewOfEnumVariant.MoveNext()

    at MerlinCRMOutlookPlugin.ThisAddIn.DBtoOutlookSyncUpdate(XmlNodeList xmlNodesToUpdate)

    in this code

           public void DBtoOutlookSyncUpdate(XmlNodeList xmlNodesToUpdate)
            {
                string sFilter = string.Empty;
         
                try
                {
                    foreach (XmlNode node in xmlNodesToUpdate)
                    {
                        sFilter = string.Empty;
                        sFilter = "@SQL=(http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/oGID = '" + node.SelectSingleNode("ExchangeID").InnerText + "')";
                        Outlook.Items Myapp1;
                        appointments.Items.IncludeRecurrences = true;
                        Myapp1 = appointments.Items.Restrict(sFilter);
                        foreach (Outlook.AppointmentItem app in Myapp1)
                        {
                               //I manipulate the appointment here           
                                app.Save();
                                app.GetInspector.Close(Outlook.OlInspectorClose.olDiscard);
                                if (Marshal.IsComObject(app))
                                {
                                    Marshal.ReleaseComObject(app);
                                }
                            }
                        }
                        if (Marshal.IsComObject(Myapp1))
                        {
                            Marshal.ReleaseComObject(Myapp1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    EmailErrorHandling(ex, "ThisAddin.DBtoOutlookSyncUpdate");
                }
            }
    I can't recreate it, I am recieving the error via email, as in the catch.  Having learnt a little bit more I will be removing the creation of myApp1 outside of the for and setting my released objects to null, but what could be the cause of the error?
    Wednesday, April 11, 2012 1:27 PM

Answers

  • Don't use a foreach loop. You can't release objects created that way such as app. Use an enumerated for loop:
     
    for (int i = 1; i <= MyApp1.Count; i++)
    {
        app = MyApp1[i] as Outlook.AppointmentItem;
        // and so on
    }
     
    Never declare the objects such as MyApp1 or app inside the loop. Declare them outside the loop and instantiate them inside the loop. That way only 1 instance is created, instead of 1 per loop pass. That also allows you to release the objects you created, such as app.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Vis Xero" <=?utf-8?B?VmlzIFhlcm8=?=> wrote in message news:8d2f6fec-b6ff-46de-8eb5-03ce1690a4be...

    I am getting this error

    System.Runtime.InteropServices.COMException (0x9494010F): Exception from HRESULT: 0x9494010F

    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)

    at System.Runtime.InteropServices.CustomMarshalers.EnumeratorViewOfEnumVariant.MoveNext()

    at MerlinCRMOutlookPlugin.ThisAddIn.DBtoOutlookSyncUpdate(XmlNodeList xmlNodesToUpdate)

    in this code

           public void DBtoOutlookSyncUpdate(XmlNodeList xmlNodesToUpdate)
            {
                string sFilter = string.Empty;
         
                try
                {
                    foreach (XmlNode node in xmlNodesToUpdate)
                    {
                        sFilter = string.Empty;
                        sFilter = "@SQL=(http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/oGID = '" + node.SelectSingleNode("ExchangeID").InnerText + "')";
                        Outlook.Items Myapp1;
                        appointments.Items.IncludeRecurrences = true;
                        Myapp1 = appointments.Items.Restrict(sFilter);
                        foreach (Outlook.AppointmentItem app in Myapp1)
                        {
                               //I manipulate the appointment here           
                                app.Save();
                                app.GetInspector.Close(Outlook.OlInspectorClose.olDiscard);
                                if (Marshal.IsComObject(app))
                                {
                                    Marshal.ReleaseComObject(app);
                                }
                            }
                        }
                        if (Marshal.IsComObject(Myapp1))
                        {
                            Marshal.ReleaseComObject(Myapp1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    EmailErrorHandling(ex, "ThisAddin.DBtoOutlookSyncUpdate");
                }
            }
    I can't recreate it, I am recieving the error via email, as in the catch.  Having learnt a little bit more I will be removing the creation of myApp1 outside of the for and setting my released objects to null, but what could be the cause of the error?

    Ken Slovak MVP - Outlook
    • Marked as answer by Vis Xero Thursday, April 12, 2012 10:07 AM
    Wednesday, April 11, 2012 2:44 PM

All replies

  • Don't use a foreach loop. You can't release objects created that way such as app. Use an enumerated for loop:
     
    for (int i = 1; i <= MyApp1.Count; i++)
    {
        app = MyApp1[i] as Outlook.AppointmentItem;
        // and so on
    }
     
    Never declare the objects such as MyApp1 or app inside the loop. Declare them outside the loop and instantiate them inside the loop. That way only 1 instance is created, instead of 1 per loop pass. That also allows you to release the objects you created, such as app.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Vis Xero" <=?utf-8?B?VmlzIFhlcm8=?=> wrote in message news:8d2f6fec-b6ff-46de-8eb5-03ce1690a4be...

    I am getting this error

    System.Runtime.InteropServices.COMException (0x9494010F): Exception from HRESULT: 0x9494010F

    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)

    at System.Runtime.InteropServices.CustomMarshalers.EnumeratorViewOfEnumVariant.MoveNext()

    at MerlinCRMOutlookPlugin.ThisAddIn.DBtoOutlookSyncUpdate(XmlNodeList xmlNodesToUpdate)

    in this code

           public void DBtoOutlookSyncUpdate(XmlNodeList xmlNodesToUpdate)
            {
                string sFilter = string.Empty;
         
                try
                {
                    foreach (XmlNode node in xmlNodesToUpdate)
                    {
                        sFilter = string.Empty;
                        sFilter = "@SQL=(http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/oGID = '" + node.SelectSingleNode("ExchangeID").InnerText + "')";
                        Outlook.Items Myapp1;
                        appointments.Items.IncludeRecurrences = true;
                        Myapp1 = appointments.Items.Restrict(sFilter);
                        foreach (Outlook.AppointmentItem app in Myapp1)
                        {
                               //I manipulate the appointment here           
                                app.Save();
                                app.GetInspector.Close(Outlook.OlInspectorClose.olDiscard);
                                if (Marshal.IsComObject(app))
                                {
                                    Marshal.ReleaseComObject(app);
                                }
                            }
                        }
                        if (Marshal.IsComObject(Myapp1))
                        {
                            Marshal.ReleaseComObject(Myapp1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    EmailErrorHandling(ex, "ThisAddin.DBtoOutlookSyncUpdate");
                }
            }
    I can't recreate it, I am recieving the error via email, as in the catch.  Having learnt a little bit more I will be removing the creation of myApp1 outside of the for and setting my released objects to null, but what could be the cause of the error?

    Ken Slovak MVP - Outlook
    • Marked as answer by Vis Xero Thursday, April 12, 2012 10:07 AM
    Wednesday, April 11, 2012 2:44 PM
  • Ken Thank you very much for all your help I am currently implementing all of your comments.

    Is there a reason why an issue I can recreate on Outlook installed on a server accessed via citrix (to do with the simultaneous items)

    isn't recreatable on Outlook installed locally either running my Addin code, or installing the addin code?

    Wednesday, April 11, 2012 3:36 PM
  • Usually, unless you take special measures, an addin running under Citrix would be installed for all users (registered in HKLM). That requires certain steps with VSTO addins.
     
    Local storage usage has to be checked. For example a construct such as Assembly.GetExecutingAssembly().Location to find the installation folder would behave differently due to shadow copy, you'd want to use Assembly.GetExecutingAssembly().CodeBase to find where you're installed.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Vis Xero" <=?utf-8?B?VmlzIFhlcm8=?=> wrote in message news:6a7e3780-5a59-444c-ac8f-a10cfd77b213...

    Ken Thank you very much for all your help I am currently implementing all of your comments.

    Is there a reason why an issue I can recreate on Outlook installed on a server accessed via citrix (to do with the simultaneous items)

    isn't recreatable on Outlook installed locally either running my Addin code, or installing the addin code?


    Ken Slovak MVP - Outlook
    Wednesday, April 11, 2012 7:51 PM