Forum Discussion
Still struggling. I get the error "The type or namespace name 'CoreWebView2InitializationCompleted' does not exist in the namespace 'Microsoft.Web.WebView2' (are you missing an assembly reference?)"
I have
using Microsoft.Web.WebView2.WinForms;
I have downloaded and installed Microsoft.Web.WebView2 v. 1.0.2739.15 from NuGet and the project has references
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.2739.15, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2739.15\lib\net462\Microsoft.Web.WebView2.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.2739.15, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2739.15\lib\net462\Microsoft.Web.WebView2.WinForms.dll</HintPath>
</Reference>
What am I misssing?
That all looks fine. Have you tried cleaning the solution? Build | Clean solution
- eJulia4 months agoTrusted User
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.
- Digiwise4 months agoTrusted User
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_PP4 months agoExperienced User
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.
Looking for something else?
Search the Community Forum for answers or find your topic and get the conversation started!
Find technical support and help for all MYOB products in our online help centre
Dig into MYOB Academy for free courses, learning paths and live events to help build your business with MYOB.