2016-04-21 83 views
1

我有以下的基本XAML:FatalExecutionEngineError包含web瀏覽器

<Window x:Class="SomeControl" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Grid> 
     <WebBrowser x:Name="webBrowser"></WebBrowser> 
    </Grid> 
</Window> 

當我試圖關閉包含我收到以下錯誤用戶控件的標籤:

Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'Some.vshost.exe'.

Additional information: The runtime has encountered a fatal error. The address of the error was at 0x7ba6a66f, on thread 0x3bd0. The error code is 0x80131623. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

我試圖撥打WebBrowser.Dispose()但它返回相同的錯誤

回答

2

我們遇到了同樣的問題。我們試圖手動處置控制,但問題仍然存在。最後,我們使用了System.Windows.Forms命名空間中的WindowsFormsHost組件和WebBrowser。

<Window x:Class="SomeControl" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<Grid x:Name="_webBrowserGrid> 
</Grid> 
</Window> 

在代碼:

var host = new System.Windows.Forms.Integration.WindowsFormsHost(); 
System.Windows.Forms.WebBrowser _webBrowser = new System.Windows.Forms.WebBrowser(); 
host.Child = _webBrowser; 
this._webBrowserGrid.Children.Add(host); 

_webBrowser.Navigate("http://www.google.com");