none
Outlook 2010 AddIn RRS feed

  • Question

  • I've developed an AddIn for Outlook 2010 which saves an email to a directory on a web server. This has been working without any problems until the user's machines were upgraded to IE11. During this upgrade the following .NET Framework 4.5.1 upgrades were also installed:

    • KB2898869
    • KB2901126
    • KB2931368

     Since then the AddIn has been failing with the following error:

    System.Runtime.InteropServices.COMException was caught
      HResult=-2147286788
      Message=The operation failed.
      Source=Microsoft Outlook
      ErrorCode=-2147286788
      StackTrace:
           at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
           at CallSite.Target(Closure , CallSite , ComObject , String )
           at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
           at CallSite.Target(Closure , CallSite , Object , String )
           at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
           at ClawsOutlookAddIn.Ribbon.SaveEmailClick(IRibbonControl control) in c:\Users\mstrydom\Documents\Visual Studio 2013\CW_Save Email\ClawsOutlookAddIn\ClawsOutlookAddIn\Ribbon.cs:line 107
      InnerException:

    The HResult is: -2147286788

    I suspect that some other security updates were also installed by the SysAdmin group since I've uninstalled these 3 updates without any success.

    The AddIn was developed using VS2012 Framework 4. The Exception is thrown when it reaches line 3.

    1.Microsoft.Office.Interop.Outlook.Explorer currentExplorer = Globals.ThisAddIn.Application.ActiveExplorer();
    2.filePath = folderPath + fileName + "_" + dateExt + ".msg";
    3.currentExplorer.Selection[1].SaveAs(filePath);

    folderPath = https://xxxx.xxxx.com.au/xxxx/xxxx/

    filename = string, e.g. "TestEmail"

    dateExt = current date and time converted to string

    Any help solving this issue would be greatly appreciated.

    
    


    • Edited by mstrydom Tuesday, September 30, 2014 3:24 AM
    Tuesday, September 30, 2014 3:22 AM

All replies

  • Firstly, Outlook does not really care (much) about .Net - it is written in unmanaged C++.

    Secondly, the error is STG_E_INVALIDNAME. What is the value of the filePath variable? Does the path exist?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, September 30, 2014 3:37 AM
  • Hi Dmitry

    Thanks for your prompt response.

    The path definitely exists - when I put the path (without the file name) in the browser, it connects. Also it worked fine till before the upgrade.

    Any ideas?

    Tuesday, September 30, 2014 5:05 AM
  • Hos about the file name? Are you sure it does not include any invalid characters, like ":"?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, September 30, 2014 5:42 AM
  • I'm pretty sure. I parse it like so:

     fileName = fileName.Replace("|", "").Replace(">", "").Replace("<", "").Replace("?", "").Replace("*", "").Replace(":", "").Replace("/", "").Replace(@"\", "").Replace("&", "-and-");

    Also when I debug I can see that it contains only valid characters.

    Tuesday, September 30, 2014 5:45 AM
  • Hello,

    Most probably you also need to replace spaces with "%20" according to the URL encoding.

    Anyway., did you try to do the same operation in Outlook manually? Do you get any error messages in that case?

    Finally, I have noticed the following line of calls:

    currentExplorer.Selection[1].SaveAs(filePath);

    I'd suggest breaking the chain of property and method calls and declare each of them on separate lines of code. Thus, you will be able to identify the problematic property or method call exactly. Moreover, you will be able to release undelying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about this in the Systematically Releasing Objects article.

    Tuesday, September 30, 2014 12:24 PM
  • Still, what is the full file name? Can you log it in your cope or look at it in the debugger?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, September 30, 2014 2:03 PM
  • Hi Dmitry

    The full file name would be something like this:

    https://xxxxxxxx.xxxxxxxxxxxx.com.au/Data/Matters/100000/100000/testIE11_3_20140930080501.msg

    Tuesday, September 30, 2014 11:20 PM
  • Hi Eugene

    Thanks for your response.

    I've replaced the spaces as suggested - no luck.

    I can save manually on my local machine. Unfortunately the AddIn saves the email to a web server, which means that I cannot emulate that manually.

    I have also broken the chain of property and method call as suggested - it is definitely breaking on the SaveAs.

    Wednesday, October 1, 2014 12:08 AM
  • SaveAs, SafeFileAs or any other method in Outlook will not work with HTTP, FTP, etc. url. It has to be a plain old file name in the form of drive:\folder\filename.ext or \\someserver\folder\filename.ext

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, October 1, 2014 12:56 AM
  • Not sure....

    It used to work for about 1 year until Windows updates were installed on the user's machines and it is still working on those machines where updates has not been installed. Has something changed in Outlook?

    Wednesday, October 1, 2014 1:16 AM
  • No, this has never worked.

    Try it in OutlookSpy: select a message, click Item button on the OutlookSpy ribbon, go to the Functions tab, select saveAs, click Call. Enter https://xxxxxxxx.xxxxxxxxxxxx.com.au/Data/Matters/100000/100000/testIE11_3_20140930080501.msg for the first parameter.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!




    Wednesday, October 1, 2014 1:42 AM