VB .net creating mailitem via Microsoft.Office.Interop works for me but errors on other machines ?

Steve Jebson
Steve Jebson used Ask the Experts™
on
VB .net creating mailitem via Microsoft.Office.Interop works for me but not others ??

They get the error...
System.BadImageFormatException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 800700c1  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).

I've already tried Target x86 in the compile options with no luck.
I've tried 2 ways of adding the Reference....

1. Add Reference/COM
2. Add via Nuget PM > Install-Package Microsoft.Office.Interop.Outlook -Version 15.0.4797.1003 (with Embed Interop Types = True)

All variations work on my machine (64 bit Win10 Administrator accounts) but not others (also 64 bit Win10 Administrator accounts)

When adding reference via COM and i check the properties i have an Identity = {00062FFF-0000-0000-C000-000000000046}\9.6\0\primary so I'm also wondering if this is a clue as the error is reported on 0006F03A-0000-0000-C000-000000000046 ??

All help appreciated
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Steve JebsonDeveloper

Author

Commented:
Imports Microsoft.Office.Interop
Public Class Form1
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim Outlook As Outlook.Application
    Dim Mail As Outlook.MailItem

    Outlook = New Outlook.Application()
    Mail = Outlook.CreateItem(Outlook.OlItemType.olMailItem)

    Mail.To = "steve.jebson@guideline.co.uk"
    Mail.Subject = "Test Email"

    Mail.Display()
  End Sub
End Class

Open in new window

John TsioumprisSoftware & Systems Engineer

Commented:
It might be related to UAC...check this discussion here : Retrieving the COM class factory for component - Outlook
Unless you have specific need to use Outlook for composing email maybe it would be a good idea to work with .NET built-in namespaces to handle emails like  System.Net.SmtpClient...the lesser the "extra" the less errors.
Steve JebsonDeveloper

Author

Commented:
Thanks for quick reply,

I'm just getting the Antivirus software turned off for the other machine (my machine has same AV software that is running) to rule this out but as we're both running the same AV i can't see that being it but i'll confirm when AV turned off...

The other part in the article was around Running as Administrator. I don't run VS as Administrator and although our accounts are administrator level I can rule this out.
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Steve JebsonDeveloper

Author

Commented:
Can confirm that turning off the Antivirus software made no difference.
Steve JebsonDeveloper

Author

Commented:
This is an internal system so Outlook is installed on all machines and we want to just prefill the email with text and attachments but the user has the final Send with any amendments they want, we also get a copy in their sent items so Outlook is our preferred route.

We're both running same OS Win 10 and same build 17134.885, i've checked that both machines have the same referenced dll when adding via COM ...

C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Outlook.dll
Developer
Commented:
Not happy that this turned out to be the solution but it is what it is !

Uninstalled Office and reinstalled, now it works !

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial