Closed mikemeinz closed 4 years ago
Thanks! We'll look into this.
This will solves the problem of not including the WebView2Loader.dll in a ClickOnce manifest.
I modified the two Microsoft.Web.WebView2.targets files in the NuGet package so that the ClickOnce (Publish) feature of Visual Studio would copy the WebView2Loader.dll to the AppPublish directory. I changed None to Content, Include to Included and PreserveNewest to Always..
Edit 14 AUG 2020: I found that there is also a Microsoft.Web.WebView2.targets file in the SOLUTIONDIRECTORY\packages\Microsoft.Web.WebView2.0.9.579-prerelease\build directory that needs to be modified the same way..
Before
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)$(EffectivePlatform)\WebView2Loader.dll">
<Link>%(Filename)%(Extension)</Link>
<PublishState>Include</PublishState>
<Visible>False</Visible>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
After
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)$(EffectivePlatform)\WebView2Loader.dll">
<Link>%(Filename)%(Extension)</Link>
<PublishState>Included</PublishState>
<Visible>False</Visible>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
This is still a problem using NuGet version 0.9.579 prelease.
We were trying to use the WebView2 control in our WinForms app and faced the exact same issue when publishing with ClickOnce. When we tried the remedy you suggested, the WebView2Loader.dll does get copied to the clickonce publish folder, but when running it, it gives the same exception.
Anything we can check? Thanks in advance!
@hpsubs I think you can also get a NullReference Exception if the WebView2 control is not properly initialized.
Here is a small example that shows awaiting EnsureCoreWebView2Async and then using the control after the CoreWebView2Ready event is thrown:
public WebView()
{
this.Load += WebView2Test_Load
InitializeComponent();
}
private void WebView2Test_Load(object sender, EventArgs e)
{
InitializeAsync();
webView2.CoreWebView2Ready += webView_CoreWebView2Ready;
}
async private void InitializeAsync()
{
await webView2.EnsureCoreWebView2Async(); // Wait for coreWebView2 initialization
}
private void browser_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
{
Debug.Print("Navigation Completed");
}
private void webView_CoreWebView2Ready(object sender, EventArgs e)
{
webView2.NavigationCompleted += browser_NavigationCompleted;
webView2.Source = new System.Uri("https://microsoft.com/", UriKind.Absolute);
}
@mikemeinz thank you for describing the additional initialization steps. Those are not explained in the tutorial, unfortunately, and I think the team should make sure to include those. @david-risney who can we get in touch with to open a bug for missing info in the tutorial? Should I open an issue in dotnet/docs? - Edit: I opened this issue: https://github.com/MicrosoftDocs/edge-developer/issues/890
One small correction for the code sample though: in your constructor method, the InitializeComponent();
invocation should go first, because that's the one that initializes the webView2
object, and both of the other calls depend on it not being null
:
public WebView()
{
InitializeComponent(); // Call this first
this.Load += WebView2Test_Load;
webView2.CoreWebView2Ready += webView_CoreWebView2Ready;
}
...
Unfortunately, even after adding @mikemeinz 's suggestions, I have a couple of problems:
InitializeComponent
attempts to add the webView2
object to the form's Controls
collection, I get a null reference exception:OK I figured out the problem.
The documentation states I should use Edge Canary, which I'm using. My current version is 87.0.630.0 (Official build) canary (64-bit)
, which is supposed to be supported because the release notes for the version of WebView2 I'm using says: minimum Microsoft Edge version 86.0.579.0.
.
Notice the installed version is x64. Before I found this issue, I found this StackOverflow thread, which states that we need to build the app for x86. Not true if the installed Edge version is x64.
I also noticed that WebView2 won't work with Edge stable version, even though the latest released version is above the minimum supported according to the release notes. My current Edge stable version is 85.0.564.44 (Official build) (64-bit)
, but unless I have Canary installed, the app will continue crashing.
So I made sure to build my app for x64 and it now works. I can open the Designer, I can run the app and see the WebView embedded in the form.
@david-risney another way to get this issue addressed is by giving the user a more useful exception message. Seeing "object reference not set to an instance of an object" is not helpful at all for this very particular case.
The original issue, ClickOnce failure due to missing WebView2Loader.dll, should be fixed and available in the latest prerelease package, 0.9.628-prerelease. Thanks!
@carlossanlop We have work on our backlog to improve the errors generated by failing to create the CoreWebView2 (most often associated with no supported runtime/browser).
The original issue, ClickOnce failure due to missing WebView2Loader.dll, should be fixed and available in the latest prerelease package, 0.9.628-prerelease. Thanks!
ClickOnce is still missing WebView2Loader.dll and the x86, x64 and arm64 directories, none of which are copied to the App.Publish sub-directories when I publish. I've tried using 0.9.628-prerelease and even 0.9.579 with the amended target files mentioned above., none of which works with ClickOnce for me. Is this just affecting me?
Can you try uninstalling and re-installing the nuget package (rather than updating)? Sometimes I find if a file has been touched then it won't overwrite it during update.
Can you try fully cleaning and then rebuilding the solution, and then try publishing?
Continuing this discussion in #528.
The original issue, ClickOnce failure due to missing WebView2Loader.dll, should be fixed and available in the latest prerelease package, 0.9.628-prerelease. Thanks!
ClickOnce is still missing WebView2Loader.dll and the x86, x64 and arm64 directories, none of which are copied to the App.Publish sub-directories when I publish. I've tried using 0.9.628-prerelease and even 0.9.579 with the amended target files mentioned above., none of which works with ClickOnce for me. Is this just affecting me?
You probably moved on but just in case, I solved the issue by using suggestion by BirsuIonut user - This seems easy to do than tinkering around with .targets files.
https://github.com/MicrosoftEdge/WebView2Feedback/issues/3172
@pipalot
I published a ClickOnce deployment and found that when deployed and the program subsequently executed, the program immediately fails with a NullReferenceException. To solve, I manually added WebView2Loader.dll to the list of files to be published. My guess is that the NuGet package should be signaling that WebView2Loader.dll should be deployed with the other WebView2 DLLs. Please consider adding WebView2Loader.dll to the list of files required at runtime. Thanks.
Versions .NET Framework 4.8 Microsoft.Web.WebView2 0.9.515-prerelease Version 84.0.529.0 (Official build) canary (64-bit) Visual Studio 2017 Version 15.9.22 Target CPU: x64 or x86 (Tried both. Fails both ways)