I run a simple C# WPF application
that uses a browser embedded in it. I have created a event when the browser navigates to the given url. But this bug comes during runtime:
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in PresentationFramework.dll
Additional information: Exception has been thrown by the target of an invocation. The code is as follows,
public MainWindow()
{
// Some initialisation
webBrowser.Navigate(requiredUrl);
}
private void webBrowser_Navigated(object sender, NavigationEventArgs e)
{
// Actions related to navigation
}
Its throwing the Exception
.
Nevermind,the problem is solved..
Move the webBrowser.Navigate(requiredUrl) to Windows_Loaded event.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Some code
webBrowser.Navigate(requiredUrl);
}
It's working fine now.
I think as Andy said the window needs a valid handle for the browser .
So it not working inside the MainWindow() function,as the handle for browser is not created in it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.