MicrosoftEdge / MicrosoftEdge/WebView2Feedback
use wpf webview in excel vsto program issue error 0x80004002 when closing excel
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
I create wpf usercontrol with webview2(version 1.0.1587.40), the control is defined like this
public partial class WebView2Wrapper : UserControl
{
private CoreWebView2 CoreWebView2 => WebView2.CoreWebView2;
private CoreWebView2Settings Settings=>CoreWebView2.Settings;
private CoreWebView2Environment Environment => CoreWebView2.Environment;
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
nameof(Source), typeof(Uri), typeof(WebView2Wrapper), new PropertyMetadata(default(Uri)));
public Uri Source
{
get { return (Uri)GetValue(SourceProperty); }
set { SetValue(SourceProperty, value); }
}
public WebView2Wrapper()
{
InitializeComponent();
WebView2.CreationProperties = new CoreWebView2CreationProperties()
{ UserDataFolder = AppDomain.CurrentDomain.BaseDirectory };
DataContext = this;
WebView2.CoreWebView2InitializationCompleted += CoreWebView2InitializationCompleted;
}
private void CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
if (e.IsSuccess)
{
Settings.IsPasswordAutosaveEnabled=true;
IsInitialized=true;
InitializeAction?.Invoke();
}
else
{
var ex = e.InitializationException;
MessageBox.Show($"{ex.Message}\n{ex.StackTrace}");
}
}
public bool IsInitialized;
public Action InitializeAction;
public void ShowDialog()
{
var window= new Window()
{
Content = this,
Topmost = true,
WindowStartupLocation = WindowStartupLocation.CenterScreen,
Width = 600,
Height = 650
};
if (IsInitialized)
{
CoreWebView2.Navigate(Source.ToString());
}
//Source = Source;
window.ShowDialog();
}
}
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WebView2"
xmlns:Wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf" x:Class="WebView2.WebView2Wrapper"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Wpf:WebView2 x:Name="WebView2" x:FieldModifier="public" Margin="5" Source="{Binding Source}"/>
</Grid>
</UserControl>
And then used it in excel vsto as follows, it works fine. but if I have ever actived the webview2 by clicking the button1, it will issue the error 0x80004002 like follows
public partial class Ribbon1
{
private WebView2Wrapper webView2;
private void button1_Click(object sender, RibbonControlEventArgs e)
{
webView2 =webView2 ?? new WebView2Wrapper()
{
Source = new Uri(
"https://www.bing.com")
};
webView2.ShowDialog();
}
}
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{7CCC5C7F-8351-4572-9077-9C1C80913835}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
at Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.get_CoreWebView2()
at Microsoft.Web.WebView2.Core.CoreWebView2Controller.get_CoreWebView2()
at Microsoft.Web.WebView2.Wpf.WebView2.Uninitialize(Boolean browserCrashed)
at Microsoft.Web.WebView2.Wpf.WebView2.Dispose(Boolean disposing)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.