xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.53k stars 506 forks source link

[Bug] Version 1.8.0 breaks VersionTracking.Track() .. #2106

Closed dooferorg closed 8 months ago

dooferorg commented 8 months ago

Edit: I made a mistake with the report as to the Platform.Init() call.. it's not inaccessible, it's just not found under 1.8.0 with the namespacing and projects before. So I could well be missing something.

Description

I get this error since updating nuget packages on a CSharp Xamarin project:

Xamarin.Essentials.NotImplementedInReferenceAssemblyException: 'This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.'

I have installed Xamarin.Essentials and it is referenced like here: https://learn.microsoft.com/en-us/xamarin/essentials/version-tracking

I also found that 'Platform.Init()' was no longer able to be called since it's been made inaccessible? Had to remove that to get it to compile but that seems it breaks everything.

So what's the fix for this?

Steps to Reproduce

  1. Update Xamarin.Essentials to 1.8.0
  2. Call VersionTracking.Track();

If you have Platform.Init() then it won't compile anyway because you've changed it to a protected method.

Expected Behavior

Same functionality as before in 1.7.3 to actually work.

Actual Behavior

Exception. Unuseable

Basic Information

1.8.0 it fails.. 1.7.x was good.

Edit:

I wrongly attributed the bug to a protected Init() method - this is not the case. It appears I am missing the whole 'Platform' object under the Xamarin.Essentials namespace and attributed the error incorrectly.

MitchBomcanhao commented 8 months ago

Sounds like you need to update xamarin forms along with essentials.

dooferorg commented 8 months ago

No, this still occurs even with everything else updated.

The issue is this project has made 'Platform.init()' protected.

jfversluis commented 8 months ago

Make sure that you updated both Xamarin.Forms and Xamarin.Essentials on all of your projects, the shared project, iOS, Android and that all the versions align. I don't see any reason why this should break. It seems to work fine in the sample app.

dooferorg commented 8 months ago

Make sure that you updated both Xamarin.Forms and Xamarin.Essentials on all of your projects, the shared project, iOS, Android and that all the versions align. I don't see any reason why this should break. It seems to work fine in the sample app.

You mean the sample Android app MainActivity.cs that calls Platform.Init() that I expressly stated is now a protected method when updating to version 1.8.0 when all 1.7.x versions work fine?

jfversluis commented 8 months ago

Still public from what I can see. The sample project is still a separate project and is bound to the same rules as your application, so if it was protected, it shouldn't be able to call it just like you.

https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/Platform/Platform.android.cs#L87-L97

dooferorg commented 8 months ago

Yes, I realized I mispoke about the Init() method (really thought that was the issue when I made the bug report) .. seems it was picking up the System 'Platform' object incorrectly and then whining about it, after my upgrade to 1.8.0.

What 1.8.0 DOES seem to break is the where the 'Platform' object even is.

I took some screenshots through my process. When I changed to explicit namespacing for the call to Platform.Init just like the sample application does, the proper error is apparent - it's not finding 'Platform' any more under the 1.8.0 nuget package.

Screenshot 2023-11-30 163806 Screenshot 2023-11-30 163826 Screenshot 2023-11-30 164136

Removing the call to 'Platform.Init()' breaks the version tracking.

Maybe the sample project needs to be updated since obviously something is different now. Maybe another package needs to be installed but it's not apparent to me what it is.

jfversluis commented 8 months ago

But that's the thing. 1.8.0 did not bring any breaking change in that regard. You can also see in the sample that the MainActivity hasn't been touched in 3 years. If there was a breaking change in this area, that would've needed an update as well, but it didn't.

I have the feeling that there might be some weird issue with different versions between projects for you or some caching of older versions. If you throw out the bin/obj folders for the projects and rebuild, does that help?

If you create a new project and add Essentials to that and try to do the same, does that produce the same result?

dooferorg commented 8 months ago

That's fair enough. I just don't understand it. I tried making a new Xamarin project and I was able to upgrade it to 1.8.0 and it kept working.

However, even removing all dependencies to make the nuget package list the exact same as my updated example app, my original app had this error. I had closed the project and cleared the bin/obj folders both times on both projects to see if there was any caching going on. I just cannot get it to work with 1.8.0 on my original app.

I do thank you for helping me work through this. It does appear that it's not a bug on this project so I'm going to close it off. I'll just stick with 1.7.7 and move on with life at this point! lol.