jamesmontemagno / InAppBillingPlugin

Cross-platform In App Billing Plugin for .NET
MIT License
581 stars 145 forks source link

Issue: Xamarin Android "Could not load file or assembly 'Microsoft.Maui.Essentials'" #596

Closed HelmuthWcs closed 1 day ago

HelmuthWcs commented 2 months ago

Hi, I tried to upgrade my Xamarin Android App to the new Project SDK format because Visual studio warn of deprecation of the old format.

After porting the App I get an exception while calling var purchase = await billing.PurchaseAsync(sku, ItemType.InAppPurchase); Exception: "Could not load file or assembly 'Microsoft.Maui.Essentials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies."

Plugin.InAppBilling 7.1.0 Xamarin.Essentials 1.8.1

Calling or not calling "Xamarin.Essentials.Platform.Init(this, savedInstanceState);" in main activity makes no difference. The library seems to think this is a Net Maui project which it isn't. Trying to install "Microsoft.Maui.Essentials" fails because of imcompability.

Vintar commented 2 months ago

Same problem

jamesmontemagno commented 2 months ago

Xamarin.Essentials is not compabitible with .NET 6+ style apps so you will want to remove that

See https://learn.microsoft.com/en-us/dotnet/maui/migration/native-essentials?view=net-maui-8.0&tabs=android

kerams commented 3 days ago

Xamarin.Essentials is not compabitible with .NET 6+ style apps

It works perfectly fine with Avalonia targetting net9.0-android.

I assume the solution here is to compile the library yourself, replace this with using Xamarin.Essentials; and add <PackageReference Include="Xamarin.Essentials" Version="1.8.1" /> here.

jamesmontemagno commented 1 day ago

It may install, but it doesn't target net6/7/8/9 in the TFMS. It is now built into .NET MAUI itself and available in any android/ios/mac/windows project regardless if you are using .net maui for the UI or not. You just want to migrate it and set a csproj reference: https://learn.microsoft.com/en-us/dotnet/maui/migration/native-essentials?view=net-maui-8.0&tabs=android