dotnet / MobileBlazorBindings

Experimental Mobile Blazor Bindings - Build native and hybrid mobile apps with Blazor
MIT License
1.2k stars 168 forks source link

Android Hybrid Template throws exception #224

Open Kukks opened 3 years ago

Kukks commented 3 years ago

ran

dotnet new -i Microsoft.MobileBlazorBindings.Templates::0.5.50-preview
dotnet new blazorhybrid -o FirstBlazorHybridApp

and then ran the android project and got this image

Eilon commented 3 years ago

Oh gosh that looks familiar but I don't recall what that's about. No changes at all in the project, or did anything change after you created the initial template?

Kukks commented 3 years ago

Oh gosh that looks familiar but I don't recall what that's about. No changes at all in the project, or did anything change after you created the initial template?

Brand new, no changes. I've tried to update to the nightly builds but no luck

Eilon commented 3 years ago

Got it, we'll take a look!

Kukks commented 3 years ago

After updating my IDE to
JetBrains Rider 2020.3 EAP 6 Build #RD-203.5600.6, built on November 4, 2020 it started working!

Very confusing that there are IDE specific bugs like this and #196

Eilon commented 3 years ago

Ah yeah it could be Rider is doing something different with how the app is deployed/run in terms of current directory, and that could certainly affect startup errors like this. That class seems to do a bit of work at startup to initialize some JSON content and if it can't find the various DLLs to load, it'll throw, and the app won't start.

skclusive commented 3 years ago

i get the same error with the same steps with newly created project for Andriod only. using Visual Studio Mac.

please share if there are any workaround available. thanks.

skclusive commented 3 years ago

issue is only with Hybrid Apps. default mobile blazor binding app works in Andriod.

jspuij commented 3 years ago

I'm pretty sure it has got to do with the fact that somehow on some platforms a newer version of System.Memory is pulled in from nuget instead of from the framework (it should pickup the framework version. I.E. the mono or .net core versions, never the nuget). The nuget version does not contain the new Span and Memory types that System.Text.Json needs.

We add a package reference to each android project through the props files inside the nuget with the right version and IncludeAssets="none" to fix this. This works for visual studio and cmdline builds.

https://github.com/xamarin/MobileBlazorBindings/blob/master/src/Microsoft.MobileBlazorBindings.WebView.Android/build/Microsoft.MobileBlazorBindings.WebView.Android.props#L12-L14

However I get a feeling that with other IDEs than visual studio 2019 for windows this does not work, which would mean that an application configuration file with the right binding redirects would need to be generated (or be made by you).

What sometimes also works is removing the reference to System.Memory inside the project file if it uses old style references with hint paths.