CefSharp with Outlook 2010 VSTO Add-in

Created on 13 Aug 2015  Â·  10Comments  Â·  Source: cefsharp/CefSharp

Hello everyone.
And so I know that it was written about this error more than once.
Directly: https://social.msdn.microsoft.com/Forums/office/en-US/8c3d0801-986e-424f-b35c-368de2a0d8e0/host-cefsharpwinform-in-outlook-2010-addin?forum=outlookdev
Indirectly: https://github.com/cefsharp/CefSharp/issues/519#
And of course I read
https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions
and
https://github.com/cefsharp/CefSharp/wiki/Output-files-description-table-%28Redistribution%29
I have read all words from this link, but could not start Outlook 2010 VSTO Add-in with CefSharp
My story:
Download CefSharp from Nuget
Packages folder includes:
• cef.redist.x64.3.2272.32
• cef.redist.x86.3.2272.32
• CefSharp.Common.41.0.1
• CefSharp.WinForms.41.0.1
Create Outlook 2010 VSTO Add-in
Add next references from CefSharp.Common.41.0.1\CefSharp\x64 and CefSharp.WinForms.41.0.1\CefSharp\x64 to my project.
• CefSharp.dll
• CefSharp.BrowserSubprocess.Core.dll
• CefSharp.Core.dll
• CefSharp.WinForms.dll
Also I put dlls in *\MyProjectPath...\ bin\x64\debug* from
*\packages\cef.redist.x64.3.2272.32\CEF\x64*
Follows dlls:
• libcef.dll
• libEGL.dll
• libGLESv2.dll
• pdf.dll
• d3dcompiler_43.dll
• d3dcompiler_47.dll
• ffmpegsumo.dll
Target Platform for solution x64, Outlook client x64
Also a I have downloaded and install VS C++ redistributables for my platform.
For plugin I have wrote a simple code :

    var browser = new ChromiumWebBrowser("www.google.com")
    {
       Dock = DockStyle.Fill,
    };
    this.Controls.Add(browser);

And... My Exception

An exception of type 'System.BadImageFormatException' occurred in Outlook2010x64.dll but was not handled in user code
Additional information: Could not load file or assembly 'CefSharp.Core.DLL' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

Additional Note:
I have not any problems with WinForm application.
I cannot change target platform to x86 because version of my build should be equals to Outlook client version.

Please help I am very disappointed in failure

Most helpful comment

Ok, so I finally was able to get it working. Here's how (for some lost souls who might want to use it),

First, u need to use the new DLL's built using #1556 and add references accordingly
Then, due to Office not looking for the unmanaged DLLs, move these DLLs to your System32 folder (if you organize it properly in your project folder, add that folder to your PATH)
Change the CefSettings.BrowserSubprocessPath = "<point to your BrowserSubProcess.exe (for me it was in the DEBUG folder)>" before you initialize your CefSettings.

and VOILA!! it works beautifully.

All 10 comments

Before you go too far with thing, it's worth checking out #351

There are certain limitations with how CefSharp is implemented. One of which is you can't use it from another AppDomain, for which I think you'll likely find an Outlook plugin will be called (Others reporting Excel plugins, so likely exactly the same).

There is a potential workaround though it likely requires quite a bit of work see https://github.com/cefsharp/CefSharp/issues/351#issuecomment-71495187

You may need to consider another CEF based project, CefGlue perhaps?

@ISulimanov Anything else before I close this?

No, Thank I found out all that I wanted, thanks for the info.

Reading through all the links above, does this mean CefSharp, cannot be used to develop a Excel-Addin (or an Office Add-in for that matter)?

Reading through all the links above, does this mean CefSharp, cannot be used to develop a Excel-Addin (or an Office Add-in for that matter)?

@smaranh Correct.

There is #1556, though it's not production ready and won't be ready anytime soon (please don't ask when it's going to be merged, you'll only annoy me).

Awesome that really helps. Let me try and add Unit Tests for #1556 and I guess we can take it from there.

P.S. Don't wish to annoy you (for sure :smirk: )

So I built the CefSharp, with the changes suggested in the PR. I then copied the DLLs over to my project (ExcelAddIn) debug folder from /WinForms.Example/bin/x64/Debug and tried debugging it. It still gives me System.IO.FileNotFoundException and Could not load file or assembly 'CefSharp.Core.DLL'.

Did I not build the changes right? Is copying over the DLLs not the right way to implement this?

Did I not build the changes right? Is copying over the DLLs not the right way to implement this?

You'll have to compile against your new dlls. Apart from that I cannot help you, I've never tried that scenario.

You should seriously consider CefGlue or ChromiumFx as alternatives.

Ok, so I finally was able to get it working. Here's how (for some lost souls who might want to use it),

First, u need to use the new DLL's built using #1556 and add references accordingly
Then, due to Office not looking for the unmanaged DLLs, move these DLLs to your System32 folder (if you organize it properly in your project folder, add that folder to your PATH)
Change the CefSettings.BrowserSubprocessPath = "<point to your BrowserSubProcess.exe (for me it was in the DEBUG folder)>" before you initialize your CefSettings.

and VOILA!! it works beautifully.

@smaranh I can´t compile the DLL´s using #1556. Please, Could you send me the DLL´s for fix the problem in my VSTO proyect. Thanks!.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amaitland picture amaitland  Â·  22Comments

canton7 picture canton7  Â·  29Comments

dinoc picture dinoc  Â·  40Comments

alphamax picture alphamax  Â·  43Comments

arvindlloyds picture arvindlloyds  Â·  25Comments