I have referred to the WindowsControlsExtensibility solution to be able to load windows Forms controls within an Addin. Basically, what I have done is create a Windows Forms user control with a WebBrowser control in it. Then, I have a WPF user control,
which contains a WindowsFormsHost control only in it, and into this WPF user control I load my Windows Forms user control, which has the WebBrowser. I use a WPF panel to load all these items into. Basically, I have some XML which I run through a transformer
to get Html, and I load that as the content of the WebBrowser control.
Everything is loading up nicely when it comes to both the WPF addin and the Windows Forms stuff. However, when I close the application, I get an error as follows:
Message="Delegates cannot be marshaled from native code into a domain other than their home domain."
Basically, I tried commenting and uncommenting bits and pieces of my code, and I found that this is the line which stops the problem if I uncomment it:
resultsPanel is a WPF panel, enquiryResults is the WPF user control which loads the WinForms addin with the webBrowser control.
Again, all of the data is being rendered correctly, I only get this error message when closing the application.
Any ideas are appreciated.
I'm having the exact same issue with the following code.
Note that it doesn't even create a System.Windows.Forms.WebBrowser, just the WindowsFormsHost is enough to cause the problem.
Any help out there?
<!-- System.Windows.Forms.WebBrowser Grid.Row="1" control added in C# -->
m_browserHost = new System.Windows.Forms.Integration.WindowsFormsHost();
Grid.SetRow( m_browserHost, 1 );
BrowserGrid.Children.Add( m_browserHost );
Here's an update. I only receive the "Delegates cannot be marshalled from native code..." exception if I create 2 or more instances of the BrowserTabPanel user control. A single instance does not generate the exception when the app shuts down.
I found a workaround.
I added an event to my add-in contract called ReleaseResources()
In my MainWindow.Closed event handler, I call ReleaseResources() on each add-in.
In my add-in that has the WebBrowser objects, I do this for each BrowserTabPanel object:
if ( m_browserTabContent !=
m_browserTabContent = null;
if ( m_browserHost != null )
m_browserHost = null;
Presto, no more exceptions during shutdown!