I have the following code written in C# WinForms:
...
SHDocVw.WebBrowser_V1 axBrowser = (SHDocVw.WebBrowser_V1)webBrowser1.ActiveXInstance;
if (axBrowser != null)
{
axBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, axBrowser, new object[] { true });
}
axBrowser.NewWindow += axBrowser_NewWindow;
...
if (!webBrowser1.IsDisposed && !webBrowser1.Url.Equals("about:blank")) //System.NullReferenceException: Object reference not set to an instance of an object.
{
webBrowser1.Refresh(WebBrowserRefreshOption.Completely);
}
I get a null reference error when running on x86 platform. When running on x64, everything is working fine. I suppose the problem is with the Interop.SHDocVw.
Edit: In the if condition, the webBrowser1.Url part becomes null. So i tried like this: (it gives me no error BUT the CONTROL is EMPTY)
private void contextMenuStrip1_Click(object sender, EventArgs e)
{
try
{
if (!webBrowser1.IsDisposed && webBrowser1.Url !=null && !webBrowser1.Url.Equals("about:blank"))
{
webBrowser1.Refresh(WebBrowserRefreshOption.Completely);
}
else if (webBrowser1.Url == null)
{
MessageBox.Show("webBrowser1.Url ");
webBrowser1.AllowWebBrowserDrop = false;//MS bug?: {"Error HRESULT E_FAIL has been returned from a call to a COM component."} System.Runtime.InteropServices.COMException
webBrowser1.ScrollBarsEnabled = false;//false--MS bug?: {"Error HRESULT E_FAIL has been returned from a call to a COM component."} System.Runtime.InteropServices.COMException
webBrowser1.ScriptErrorsSuppressed = false;
WinInetInterop.RestoreSystemProxy();
SHDocVw.WebBrowser_V1 axBrowser = (SHDocVw.WebBrowser_V1)webBrowser1.ActiveXInstance;
if (axBrowser != null)
{
axBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, axBrowser, new object[] { true });
}
axBrowser.NewWindow += axBrowser_NewWindow;
webBrowser1.Url = new System.Uri("https://evidentacimitir.com/ProfitshareAds.html", System.UriKind.Absolute);
webBrowser1.WebBrowserShortcutsEnabled = false;
webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);
webBrowser1.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.webBrowser1_Navigated);
}
}
catch (Exception ex)
{
ExceptionReportHelper.Exception(ex);
}
}
How can I fix this problem to work also on x86 platforms?
Thanks
question from:
https://stackoverflow.com/questions/65641290/shdocvw-works-only-with-win-10-x64-version 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…