Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CefSharp with Outlook 2010 VSTO Add-in #1191

Closed
ISulimanov opened this issue Aug 13, 2015 · 15 comments
Closed

CefSharp with Outlook 2010 VSTO Add-in #1191

ISulimanov opened this issue Aug 13, 2015 · 15 comments

Comments

@ISulimanov
Copy link

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: #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

@amaitland
Copy link
Member

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 #351 (comment)

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

@amaitland
Copy link
Member

@ISulimanov Anything else before I close this?

@ISulimanov
Copy link
Author

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

@smaranh
Copy link
Contributor

smaranh commented Mar 18, 2016

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)?

@amaitland
Copy link
Member

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).

@smaranh
Copy link
Contributor

smaranh commented Mar 18, 2016

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 😏 )

@smaranh
Copy link
Contributor

smaranh commented Mar 22, 2016

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?

@amaitland
Copy link
Member

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.

@smaranh
Copy link
Contributor

smaranh commented Apr 28, 2016

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.

@davidpg1
Copy link

davidpg1 commented Jul 4, 2018

@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!.

@zhanghaigang666
Copy link

I encountered the same problem. Is there a clear demo on how to introduce cefsharp into the office vsto project?

@amaitland
Copy link
Member

Try using https://github.com/NetOfficeFw to create your Add-in instead of VSTO.

@zhanghaigang666
Copy link

Try using https://github.com/NetOfficeFw to create your Add-in instead of VSTO.

I have known about NetOffice, and it is not suitable for our project. I am now worried about how to make cefsharp be used normally in the existing vsto projects. So far I have not found a suitable method, and I found CefGlue and ChromiumFx The demo can't be used normally, it seems that no one has maintained it, it is very tangled

@amaitland
Copy link
Member

Using CefSharp directly in a VSTO add-in is not supported. You'll need to run CefSharp out of process.

https://github.com/stever/AppHostCefSharp has an example that you might be able to adapt.

There won't be an official example as I don't own a copy of Microsoft Office.

@jozefizso
Copy link
Contributor

@zhanghaigang666 CefSharp requires to run in the default AppDomain. As VSTO will isolate you add-in in its own AppDomain, CefSharp won't work there.

You can use NetOffice to write the add-in, or use the standard COM interfaces available (the IDTExtensibility2). You must register the add-in directly as a .NET COM Add-in in Office apps so it runs in the default AppDomain.

You cannot use add-in isolation like COM Shim wrappers.

Alternatively, you may try to use other CEF libraries which does not require to be run in default AppDomain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants