Forum Discussion
That all looks fine. Have you tried cleaning the solution? Build | Clean solution
Nice thought but sadly not the answer. Have rebooted and tried other solutions that use mostly the same code but no further forward. The problem arisies consistently on all the versions of the app I have tried.
Will resume picking over my csproj files tomorrow so if you have any more brilliant thoughts happy to hear about them.
- Digiwise5 days agoTrusted Partner
What platform are you building for? .Net Core, WPF or WinForms
Mine is WPF based (long story), but I didn't use CoreWebView2InitializationCompleted.
namespace DigiwiseDOM { using Microsoft.Web.WebView2.Core; using System; using System.Threading.Tasks; using System.Web; /// <summary> /// Interaction logic for CloudLogin.xaml /// </summary> public partial class CloudLogin : System.Windows.Window { public CloudLogin(string url) { this.InitializeComponent(); Browser.NavigationCompleted += WebBNavigationCompleted; _ = InitializeBrowser(url); } public string GetOAuthCode() { this.ShowDialog(); // The dialog will close once the user has granted access to MYOB and the OAuth code is in the URL // Extract the oAuth code and return it var uri = Browser.Source; var queryParams = HttpUtility.ParseQueryString(uri.Query); var code = queryParams["code"]; Browser.Dispose(); // Prevented an exception that occcurred on exiting the application if we remove this line return code; } private async Task InitializeBrowser(string url) { var userDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DigiwiseQuickExtract"; var env = await CoreWebView2Environment.CreateAsync(null, userDataFolder); await Browser.EnsureCoreWebView2Async(env); Browser.Source = new UriBuilder(url).Uri; } private void WebBNavigationCompleted(object sender, EventArgs e) { var webB = (Microsoft.Web.WebView2.Wpf.WebView2)sender; // Check if OAuth code has been returned and close dialog if it has var uri = webB.Source.ToString(); if (uri.Contains("code=")) { this.Close(); } } } }
- Steve_PP5 days agoExperienced Partner
CoreWebView2InitializationCompleted is a public event of WebView2 in the Microsoft.Web.WebView2.WinForms namespace. If your project is WinForms, you need to ascertain why your WebView2 class is not referencing Microsoft.Web.WebView2.WinForms.
Right-click on 'WebView2' on this line and click 'Go to definition'
var webView2 = new WebView2
You should end up looking at this file (scroll to the top.) Presumably you are not. You need to work out why. Recheck your references.