MobileBlazorBindings icon indicating copy to clipboard operation
MobileBlazorBindings copied to clipboard

BlazorHybrid template error on runtime: Type initializer for ElementReferenceJsonConverter threw

Open ricardoromaobr opened this issue 3 years ago • 13 comments

When I run the android project on macOs the screen show and throw a error

image_2021-03-11_164449

The screen is showed and desapear and this error take place.

But I have ran the others projects with success: iOS; macOs.

Just the android project that does not work.

The BlazorMobileBindings template work with not any problem all project works.

ricardoromaobr avatar Mar 11 '21 19:03 ricardoromaobr

I know I've seen this before, but again I can't figure out where! It's odd that it's just Android, because this code should be quite similar, if not identical, on all platforms.

Did you by any chance use Debug or Release mode? Or do some sort of app trimming? Or is this just the basic template running with all default settings?

Eilon avatar Mar 16 '21 20:03 Eilon

Just the basic template running with all default settings. My machine is a macOs catalina, but at my work I have imac with big sur. And I have the same error.

ricardoromaobr avatar Mar 17 '21 00:03 ricardoromaobr

image_2021-03-16_222744

On windows, the android works fine! What would be if the template is that same ? The template repository is the same? Or something is wrong in the version for macOs. Or something is wrong in the msbuild pipeline on macOs?

ricardoromaobr avatar Mar 17 '21 01:03 ricardoromaobr

https://user-images.githubusercontent.com/7851330/111405651-9f99fd00-86af-11eb-92b5-a2211dd5df32.mov

This is what are going when the app is started.

ricardoromaobr avatar Mar 17 '21 02:03 ricardoromaobr

Hi guys. I have the identical problem, but it happens when I run the iOS project, not Android. Any progress about it?

tabachuk avatar Apr 21 '21 13:04 tabachuk

So I added this code to iOS .csproj file and now it works fine for me. Hope it is useful to someone.

<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.4">
<IncludeAssets>none</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Buffers" Version="4.5.1">
<IncludeAssets>none</IncludeAssets>
</PackageReference>
</ItemGroup>

tabachuk avatar Apr 26 '21 12:04 tabachuk

I am also experiencing this on the Android side. Curiously though, if I close the app in the simulator (which disconnects my VS debugger), then relaunch it, the error does not appear.

GravlLift avatar Aug 13 '21 17:08 GravlLift

Experiencing the same as @GravlLift

GarageGadget avatar Nov 08 '21 10:11 GarageGadget

I am having the same issue as @GravlLift. My PC is running on Win10 and I am using the VS 2022.

troshanov avatar Nov 21 '21 15:11 troshanov

UPDATE: I managed to fix the issue by updating the System.Net.Http.Json (in the shared project) and System.Text.Encodings.Web (in Android project) to 6.0.0. In the initial template they are still supporting 3.X.X versions. @GarageGadget @GravlLift @ricardoromaobr please advise if this fixes the problem for you as well, so the issue can be addressed accordingly.

troshanov avatar Nov 21 '21 16:11 troshanov

UPDATE: I managed to resolve the issue by updating the packages to latest versions, followed by Clean and Rebuild.

GarageGadget avatar Nov 22 '21 13:11 GarageGadget

@Eilon Is there going to be an update for the hybrid templates so this issue can be avoided in the future?

troshanov avatar Nov 22 '21 14:11 troshanov

i fix this issue by updating System.Net.Http.Json(in app project) and System.Text.Encodings.Web(in android project) and System.Text.Json(in windows project) to the latest version(6.0.0) and subsequently build the solution.

moslemkh avatar Nov 30 '21 17:11 moslemkh