Eilon / MauiHybridWebView

MIT License
206 stars 45 forks source link

Null Reference Exception when targeting .Net 8 Preview #26

Closed DaveNatalieTripArc closed 1 year ago

DaveNatalieTripArc commented 1 year ago

Steps to reproduce

Clone the repo, and change the TargetFramework in the MauiCSharpInteropWebView to

<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>

When running the application, you'll get a null reference exception with no additional info (all threads are executing external code).

I am currently using Maui 8.0.0-preview.7.8842

Edit: It works on Windows, but does not work on Android. I have not tried iOS.

nelsonrc commented 1 year ago

Steps to reproduce

Clone the repo, and change the TargetFramework in the MauiCSharpInteropWebView to

<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>

When running the application, you'll get a null reference exception with no additional info (all threads are executing external code).

I am currently using Maui 8.0.0-preview.7.8842

Edit: It works on Windows, but does not work on Android. I have not tried iOS.

Same issue on Android Working on iOS!!!

Eilon commented 1 year ago

Thanks for the report, I'll try this out. Hopefully an easy fix!

Eilon commented 1 year ago

Hi @DaveNatalieTripArc , @nelsonrc - I tried using .NET 8 Preview 7 and was able to run it fine after changing the TargetFrameworks entries. Are you able to run the app with the debugger and see what the exception is?

To enable ALL exceptions, go to Debug/Windows/Exception Settings: image

And make sure there's a CHECKED checkbox (not just a square) for Common Language Runtime Exceptions: image

Eilon commented 1 year ago

Alright thanks to a stack trace from @bethmassi I think I know the bug. I'm testing a fix.

I believe the bug is in this line: https://github.com/Eilon/MauiHybridWebView/blob/d21a70d7e46310d84e3e2a0a414cb012b790baa2/HybridWebView/HybridWebViewHandler.cs#L35

And change the ! to a ? so that the field can be null (which is fine on .NET 8, but is needed on .NET 7).

Eilon commented 1 year ago

The MAUI change that necessitated this change here is this PR: https://github.com/dotnet/maui/pull/16032

Now that the fix is checked in here, I'll see when I can push a NuGet package update. Thanks for the report!

DaveNatalieTripArc commented 1 year ago

Thanks for fixing that so quickly. I look forward to trying out the peview-4 release once it becomes available.

Eilon commented 1 year ago

@DaveNatalieTripArc the fix should be available in the updated package: https://www.nuget.org/packages/EJL.MauiHybridWebView/1.0.0-preview4

nelsonrc commented 1 year ago

I update the package and working now!!!!

Thanks

DaveNatalieTripArc commented 1 year ago

With a quick check, it looks like the null reference exception is gone!

However, on Android, my page doesn't actually load, and I get a Connection Refused message.

image

This same code is working on Windows, but there is probably something wrong I am doing on my end. I'll look into it more when I get a chance.

DaveNatalieTripArc commented 1 year ago

Okay, this is working properly, the problem is on my end.

I was trying to share my Raw Html in a separate assembly, so that two different apps can use the same web content.

I added this to my shared library.

    <ItemGroup>
        <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
    </ItemGroup>

It seems to work on Windows, but Android doesn't like it. In any case, this has nothing to do with the null reference exception we were getting.

Thanks again for the fix.

Eilon commented 1 year ago

@DaveNatalieTripArc can you log a new bug with a full repro app so I can investigate?