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

Null Reference Exception on start up #263

Closed
dan-toadllc opened this issue Jun 11, 2020 · 7 comments
Closed

Null Reference Exception on start up #263

dan-toadllc opened this issue Jun 11, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@dan-toadllc
Copy link

dan-toadllc commented Jun 11, 2020

I'm getting a NullReferenceException error on this line in Form1.Designer.cs:

this.Controls.Add(this.webView21);

I don't see anything that is null.

AB#26932580

@mikemeinz
Copy link

@dan-toadllc

I had problem similar (if not the same) as yours. It turned out that the directives in the NuGet package don't specify that the the WebView2Loader.dll should be included. Maybe my solution will help you.

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 and Include to Included. This has been reported as a bug in Issue 228.

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>

@pagoe-msft pagoe-msft added bug Something isn't working .NET labels Jun 12, 2020
@champnic
Copy link
Member

@dan-toadllc Could you try @mikemeinz change above and see if that fixes it? If so, we'll fix this as part of #228.

@champnic
Copy link
Member

@dan-toadllc We haven't heard back in a month so I'm closing this for now. If you are still running into this issue please reactivate and we'll take another look. Thanks!

@alexlogiclab
Copy link

alexlogiclab commented Jul 18, 2020

This is definitely an issue. I am not sure where you make the changes you have suggested mikemeinz....

I really want to use this control but it seems very tricky to get running at the moment. Any help would be greatly appreciated :-)

@mikemeinz
Copy link

mikemeinz commented Jul 18, 2020

@alexbitsnz

On my PC, there are two files named Microsoft.Web.WebView2.targets. One of them is in C:\Users\USERNAME\.nuget\packages\microsoft.web.webview2\0.9.538-prerelease\build\native. The other file is in C:\Users\USERNAME\.nuget\packages\microsoft.web.webview2\0.9.538-prerelease\build. I used Windows Explorer Search to find them.

I made the same edit in both files. See Jun 12 post above.

@alexlogiclab
Copy link

Thank you Mike, that helped a lot :-)

@champnic
Copy link
Member

@alexbitsnz Glad @mikemeinz 's fix helped. We're tracking that issue in #228.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants