Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code working well on my Development PC (Windows XP with Office 2010). But when I run the executable on a Windows 7 PC with Office 2010, I get the following error:
"The operation failed because of a registry or installation problem. Restart Outlook and try again. If the problem persists, reinstall."
The error happens on this line:

Dim inbox As Folder = ns.GetSharedDefaultFolder(recipient, OlDefaultFolders.olFolderInbox)

I have a seperate application running on the same production PC that uses Microsoft.Office.Outlook.Interop to convert .MSG files to .PDF that runs without issue.

VB
Imports Microsoft.Office.Interop.Outlook

        log = New cLog()
        Dim AppKeys As IDictionary = ConfigurationManager.GetSection("AppKeys")
        Dim app As New Microsoft.Office.Interop.Outlook.Application()
        Dim box As String
        log.Write("Starting to retrieve mail.")
        Try
            box = AppKeys("mailbox")
            tempLoc = Environment.CurrentDirectory & "\" & ConfigurationManager.AppSettings("TempLoc")
            Dim ns As Microsoft.Office.Interop.Outlook.NameSpace = app.Session
            log.Write("Namespace is: " & ns.CurrentProfileName)
            Dim recipient As Recipient = ns.CreateRecipient(box)
            log.Write("recipient is: " & recipient.Name)
            recipient.Resolve()
            log.Write("recipient resolved")
            Dim inbox As Folder = ns.GetSharedDefaultFolder(recipient, OlDefaultFolders.olFolderInbox)
            log.Write("Got inbox")
            Dim subject As String
            Dim mailCount As Int32 = 0
            log.Write("There are " + inbox.Items.Count.ToString() + " Emails in " + box)
            For Each mm As MailItem In inbox.Items
                If Not subject Is Nothing Then
                    For Each attach As Attachment In mm.Attachments
                        attach.SaveAsFile(tempLoc & filename & attach.FileName.Substring(attach.FileName.Length - 4, 4))
                    Next
                        ''Save email message as msg and create idx file for it
                        filename = filename.Substring(0, filename.Length - 2) & "_" & count + 1
                        mm.SaveAs(tempLoc & filename & ".msg", OlSaveAsType.olMSG)
                End If
            Next
        Catch ex As System.Exception
            log.Write("Excpetion getting mail: " & ex.Message)
        End Try
        app.Quit()



Any thoughts would be greatly appreciated.

Thank you,

tshaffer
Posted
Updated 29-Aug-18 6:15am

Started experiencing the same error out of the blue yesterday in Outlook VBA. Finally found a workaround.

Changed this:
VB
Set teamBox = objNS.CreateRecipient("Our.Shared.Mailbox@domain.tld")
Set olTeamBoxItems = objNS.GetSharedDefaultFolder(teamBox, olFolderInbox).Items


To this:
VB
Set olTeamBoxItems = objNS.Folders("Our Shared Mailbox").Folders("Inbox").Items
 
Share this answer
 
v2
In C# using Outlook = Microsoft.Office.Interop.Outlook, my solution looked like this:

Outlook.NameSpace nameSpace = olApp.GetNamespace("Mapi");
Outlook.MAPIFolder inbox = (Outlook.MAPIFolder)nameSpace.Folders["The Shared Folder"].Folders["Inbox"];
 
Share this answer
 
Comments
Richard Deeming 30-Aug-18 10:44am    
This is exactly the same code as solution 1.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900