Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebView2 in WPF VSTO Addin does not load #505

Closed
kjb15 opened this issue Oct 6, 2020 · 10 comments
Closed

WebView2 in WPF VSTO Addin does not load #505

kjb15 opened this issue Oct 6, 2020 · 10 comments
Labels
feature request feature request tracked We are tracking this work internally.

Comments

@kjb15
Copy link

kjb15 commented Oct 6, 2020

Environment: Visual Studio 2017 Community
NuGet: Microsoft.Web.WebView2, 0.9.628-prerelease
Net Framework: 4.6.2
Project type: VSTO Outlook Addin
Reference: https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/wpf

WebView2 does not load any URL inside the control while docked in UserControl of VSTO Addin project

XAML page:
webView2WPF03

XAML.cs page:
wpf04

Addin.cs page:
wpf05

Outlook Custom Task Pane view:
webView2WPF02

Can someone look into this issue?

Thanks

@pagoe-msft pagoe-msft added bug Something isn't working feature request feature request tracked We are tracking this work internally. and removed bug Something isn't working labels Oct 6, 2020
@champnic
Copy link
Member

champnic commented Oct 6, 2020

Have you checked out the other VSTO issues? In particular:
#187

Was WebView2 working in your VSTO before docking it in the UserControl?

I also noticed you are using the Source property rather than EnsureCoreWebView2Async. That does implicit initialization and will create a default UserDataFolder where the code lives, which will be in C:\Program Files... and the Runtime won't have write permissions, so will fail. You need to specify a UserDataFolder somewhere else, using EnsureCoreWebView2Async, or CoreWebView2CreationProperties with Source property.

@kjb15
Copy link
Author

kjb15 commented Oct 9, 2020

Thanks @champnic Appreciate the quick response. Certainly, this worked for me:

var env = await CoreWebView2Environment.CreateAsync(null, @"C:\temp");
await webView.EnsureCoreWebView2Async();

Wondering about what should be the workaround while deploying to Production?

@champnic
Copy link
Member

champnic commented Oct 9, 2020

This isn't a workaround per se, it's just a necessary part of writing the VSTO with WebView2. That said, you should probably pick a different location for the UserDataFolder (besides C:\temp) before deploying to production, to make it less accessible and unique to your VSTO. Potentially somewhere in the AppData folder?

@champnic
Copy link
Member

champnic commented Oct 9, 2020

I'm going to close this issue. If you'd like me to reopen please let me know with extra details, or open a new issue if you run into something else. Thanks!

@abhinovpankaj
Copy link

abhinovpankaj commented Jan 7, 2022

I am facing this similar issue.
Have tried the method mentioned in the thread but it still fails to resolve my issue.

Code in my WPF mainwindow.xaml.cs#

public LoginControl()
        {
            InitializeComponent();

            webView.Initialized += WebView_Initialized;
            webView.BringIntoView();
            
        }

        private void  WebView_Initialized(object sender, EventArgs e)
        {
             InitializeAsync();
        }

     
        public async void InitializeAsync()
        {
            string folder = @"C:\temp"; //Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var env = await CoreWebView2Environment.CreateAsync(null, folder);
            await webView.EnsureCoreWebView2Async(env);

            webView.CoreWebView2.Navigate("https://www.microsoft.com");
            webView.CoreWebView2.WebResourceResponseReceived += CoreWebView2_WebResourceResponseReceived;

        }

Additonally if I diectly call InitializeAsync from LoginControl constructor, I get below exception

System.InvalidOperationException: 'EnsureCoreWebView2Async cannot be used before the application's event loop has started running.'
image

@champnic
Copy link
Member

champnic commented Jan 7, 2022

Hey @abhinovpankaj - what is the error you get when trying the "C:\temp" folder?

@abhinovpankaj
Copy link

webview just wont display the page.

@champnic
Copy link
Member

champnic commented Jan 7, 2022

@abhinovpankaj do you have a sample app you would be able to share that reproduces this issue? Thanks!

@abhinovpankaj
Copy link

https://github.com/point5nyble/OutlookPopup

Git repo with the source code. it's an Outlook Add-on project. It's the withLicensing__ branch .
It's in development so few extra projects and a bit of test and trial code here and there
But the webview2 logic has been written in LoginControl.

Thanks
Abhinov

@abhinovpankaj
Copy link

abhinovpankaj commented Jan 10, 2022

@champnic

@abhinovpankaj do you have a sample app you would be able to share that reproduces this issue? Thanks!

Did you get chance to check on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

4 participants