I manage an Excel addin in C#, using VS2017.
The addin uses a WebBrowser that is used to access specific web pages. It recently stopped running on every version of the addin I have (dev and release), even though I haven't seen any patch note about it.
Basically, the WebBrowser control doesn't shows up anymore. All its property are correctly set, the html document is correctly loaded upon navigation but nothing is displayed in place of the control. The control and its parents component are set to visible and are correctly loaded with correct size and coordinates.
I have set a new blank project with Visual Studio and tested it with nothing but a WebBrowser control trying to display google and about:blank, with no success. here is the code below :
ThisAddin.cs :
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new MyRibbon();
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
MyRibbon.cs :
[ComVisible(true)]
public class MyRibbon : Office.IRibbonExtensibility
{
private Office.IRibbonUI ribbon;
public MyRibbon()
{
}
#region IRibbonExtensibility Members
public string GetCustomUI(string ribbonID)
{
return GetResourceText("WebBrowserShowcase.MyRibbon.xml");
}
#endregion
#region Ribbon Callbacks
//Create callback methods here. For more information about adding callback methods, visit https://go.microsoft.com/fwlink/?LinkID=271226
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
this.ribbon = ribbonUI;
}
public void openWebBrowser_click(IRibbonControl control)
{
WebPanel panel = new WebPanel();
panel.ShowWebBrowser();
}
public string getTabLabel(IRibbonControl control) { return "WebBrowserShowCase"; }
#endregion
}
MyRibbon.xml :
<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon>
<tabs>
<tab id="myRibbon" getLabel="getTabLabel">
<group id="MyGroup" label="My Group">
<button id="OpenWebBrowser" size="large" onAction="openWebBrowser_click" imageMso="_3DDirectionGalleryClassic"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
WebPanel.cs :
public class WebPanel : UserControl
{
TableLayoutPanel tableLayoutPanel1;
WebBrowser _webBrowser;
public WebPanel()
{
InitializeComponent();
WebBrowserHelper.FixBrowserVersion();
}
public void ShowWebBrowser()
{
CustomTaskPane taskPane = Globals.ThisAddIn.CustomTaskPanes.Add(this, "title", Globals.ThisAddIn.Application.ActiveWindow);
DisplayTaskPane(taskPane);
Navigate();
}
private void DisplayTaskPane(CustomTaskPane taskPane)
{
taskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft;
taskPane.Width = Convert.ToInt32(Globals.ThisAddIn.Application.ActiveWindow.Width);
taskPane.DockPositionRestrict = Microsoft.Office.Core.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
taskPane.Visible = true;
tableLayoutPanel1.Dock = DockStyle.Fill;
tableLayoutPanel1.Visible = true;
_webBrowser.Dock = DockStyle.Fill;
_webBrowser.Visible = true;
}
private void Navigate()
{
_webBrowser.Navigate(new Uri("about:blank"));
}
}
For convenience purposes I removed some of the auto generated code and the WebBrowserHelper that you will find here : WebBrowserHelper
Here is an image of the WebPanel, it is a WebBrowser in a TableLayout component :
And here is the result when starting the project, going into the ribbon and clicking the button :
As you can see, the WebBrowser isn't displayed. I tried with and without Uri, about:blank and google, but the result is always the same.
Does anyone have an idea of what might be the problem here?
EDIT :
So apparently, the WebBrowser still works on Windows 7, but not on Windows 10.
I have checked it with several machines which all have the same internet explorer version (11.0.17134.829).
If the OS is the problem, is there anything I can do?