-
Notifications
You must be signed in to change notification settings - Fork 55
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
Is WebView2 supported in Excel VSTO Add-in? #187
Comments
Hey @Yuandi-Jin we're enlisting help from the VSTO Add-in team to look into this as none of us on the WebView2 team is very similar with that. Will get back to you! |
@liminzhu Cool! As I said I was able to use WebView2 in a few other types of projects. Looking forward to the feedback and insights from VSTO Add-in team. For completeness, here are the versions: |
Hi @Yuandi-Jin, I work on the Office Developer Tools team in Visual Studio and we haven't tested this before you opened this issue so I'm looking into it now. I did find that the WebView2 control does appear in the toolbox when I have a Windows Form open in the designer, in a VSTO Add-in project, when I installed WebView 2.0.9.515-prerelease. When I tried to run the Add-in however, I ran into the issue described here, MicrosoftDocs/edge-developer#693 where the CoreWebView2 was null. I would expect that this control should work similar to how it does with Winforms but there are some known issues that may effect this so once issues like (693) are fixed I'll try it again and I'll update this issue. |
Hi @John-Hart , re: Form (Windows Forms) item re: User Control (WPF) item |
@Yuandi-Jin can you check if Tools > Options > Windows Forms Designer > General > "Automatically Populate Toolbox" = True in Visual Studio? Also does it appear after a build? If that doesn't work try adding it manually, right click on toolbox select Choose Items... and Browse to and select the %ProjectName%\packages\Microsoft.Web.WebView2.0.9.515-prerelease\lib\net462\Microsoft.Web.WebView2.WinForms.dll |
I should also say, if you add the control manually to the toolbox, I would recommend not leaving it in the toolbox since it points to the one in the specific project folder and not a shared location. It should work when the packages is added to the project, this is more of a test to see if it can be added successfully. |
@John-Hart
Then I hit a null reference error. Inspired by 182, I fixed it: After that, I got this Now I don't see any errors but the browser is blank. CoreWebView2 is null. I guess both paths (WinForms, WPF) are blocked similarly. |
@Yuandi-Jin The loader issue should be fixed in newer SDKs. For the UserDataFolder, you can set it using EnsureCoreWebView2Async instead of setting the Source property:
|
Please reply or reopen this issue if it's still not working for you. |
I tried again with WebVew2 v0.9.579-prerelease and Edge Version 87.0.630.0 (Official build) canary (64-bit).
Exception:
I cannot reopen the issue. Please reopen it for me. Thanks. |
Update: updated SDK to v0.9.628-prerelease. Now I'm not getting any issue from the loader. I guess that's been fixed since I do see x64 and x86 folders under Debug or Release. |
Thanks @Yuandi-Jin I've changed this item to a bug on our end to track this. We'll take a look. |
@Yuandi-Jin Do you think the remaining issue could be related to #431? |
@champnic That NRE in #437 looks familiar. I tried both Form Windows Forms and User Control (WPF) in VSTO add-in at first. Back to my question, did I use your code (wrapped in InitializeWebView2Async) in the right way? Thanks. |
Ah, sorry I missed that you had switched to WPF. Is your XAML code setting "Source"? If so, you need to remove that. |
My XAML code was not setting Source. Inspired by that comment, I was able to go further on the track of Form (Windows Forms). I don't want to add too much distraction but FWIW I saw the Bing page successfully in WebView2 after commenting out a line in MainForm.Designer.cs
It's a hack. We all know that modifying the auto-generated designer code is bad. You may want to track that separately. The MainForm class:
|
Now back to the User Control (WPF) track.
The problem is that after closing Excel (since it's an Excel add-in), I got InvalidOperationException.
|
Re: Winforms - Commenting out Source property is the right way to do it currently. I agree that it's kind of bad though, so we're currently making changes to not require the Designer to specify the Source property unless necessary (because it kicks off the implicit initialization). Re: WPF - I'm not familiar with WPF for Excel add-in, so if you could share a sample app that would be appreciated. It seems like one of the restrictions they have is to call Show instead of ShowDialog - I don't think WebView2 would be restricting that (you could test by removing WV2 and just using a button or something). For the InvalidOperationException, Dispose needs to be called on the same thread as the WebView2 control. You probably need to clean it up using .Close() or .Dispose() yourself when the MainWindow is closing. Can you give that a try? |
@Yuandi-Jin For WPF, initializing CoreWebView2 can be done in the window "Loaded" event handler. It needs to use "await" so add "async". MainWindow.xaml
MainWindow.xaml.cs
|
@cgeier Thanks for sharing the code. Now I'm not seeing any exceptions. |
@champnic After calling Dispose() properly I can run my test add-in successfully. ShowDialog() works too. Thanks. |
That's great news! Glad you've got it all working now. Thanks! |
@Yuandi-Jin You're welcome. I saw one of the earlier posts where @John-Hart talked about the adding the WebView2 control to the ToolBox manually. When the WebView2 NuGet package is installed the following occurs: If The necessary files/folders are copied from If manually adding the WebView2 control to the ToolBox, it may be better to reference the .dll files in |
The code for WinForms is similar, except the "Load" event handler is
Here's the complete WinForms demo project: WebView2Test.zip |
This issue doesn't seem to be resolved. I am using vb.net to attempt to place WebView2 control into an excel vsto addin task pane and I am having no luck. I have used the EnsureCoreWebView2Async to attempt to get the core object to populate and there is simply nothing that will work. Converting the following lines to vb: C# VB.NET Still the core object will not assign. I am working off the Microsoft.Web.WebView2.1.0.674-prerelease. I thought that it may be the browserexcutablefolder causing it to fail, but that doesn't seem to work when I tried set that either. I am at a loss... |
I tried sample projects in https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/wpf and https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/winforms, they worked.
Then I created a new Excel VSTO Add-in project in Visual Studio. After addingWebView2 package, I could not use it. So, is WebView2 supported in Excel VSTO Add-in project?
Details:
AB#28795785
The text was updated successfully, but these errors were encountered: