getsentry / sentry-xamarin

Sentry for Xamarin Native and Xamarin.Forms
https://docs.sentry.io/platforms/dotnet/guides/xamarin/
44 stars 11 forks source link

'Xamarin.Essentials.NotImplementedInReferenceAssemblyException' despite direct reference #149

Closed abenadar closed 1 month ago

abenadar commented 7 months ago

Environment

I have three seperate projects each targeting a different platform.

<UseMauiEssentials>true</UseMauiEssentials> is used for all, but no Maui itself.

Most source files lie in a shared project (not a CL) reference by the tree projects.

Installed Workload Id      Manifest Version       Installation Source
---------------------------------------------------------------------
maui-windows               8.0.7/8.0.100          VS 17.9.34723.18
maccatalyst                17.2.8004/8.0.100      VS 17.9.34723.18
android                    34.0.52/8.0.100        VS 17.9.34723.18
ios                        17.2.8004/8.0.100      VS 17.9.34723.18

Steps to Reproduce

  1. Set up a project like above.
  2. Add a package reference to Sentry.Xamarin 2.0.0 in any of the three projects.
  3. Add a call to the SDK in a source file contained in the shared project:

      ```
     SentryXamarin.Init(c => 
       {
           c.Dsn = "https://{...}";
           c.Debug = true;
           c.TracesSampleRate = 1.0;
       });
    ```
  4. Build the project.

Expected Result

The project builds successfully.

Actual Result

The build fails with a 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 could see this appearing if the shared project was a class library which itself had the only reference to Sentry.Xamarin. However, the main projects do contain the reference.

Since the issue is apparently caused by the underlying Xamarin.Essentials reference I was thinking about using the Maui package, but it appears to use Extensions unavailable in a pure Xamarin project.

kkabala commented 7 months ago

Same issue here. At the moment it looks like Sentry is not compatible with Xamarin apps

abenadar commented 6 months ago

Same issue here. At the moment it looks like Sentry is not compatible with Xamarin apps

At least not Xamarin apps relying on MAUI essentials rather than Xamarin.Essentials, which looks like a massive oversight to me. I bumped this issue to the customer support as I was in contact with them anyway. Ticket has fallen stale since then. Guess I'll have to look for alternatives.

bitsandfoxes commented 6 months ago

Hey @abenadar, @kkabala! Sorry about that, this slipped past by us somehow. We're looking into it.

lucas-zimerman commented 6 months ago

Hi, this SDK is only compatible with Sentry Xamarin but not MAUI. For MAUI we have another SDK that you can check out here: https://docs.sentry.io/platforms/dotnet/guides/maui/ please let us know if the MAUI SDK is working with your project.

marwalsch commented 6 months ago

@lucas-zimerman Thanks for looking into this.

The MAUI package as documented is not an option for me as I am not using MAUI as a framework, merely its Essentials libraries. However, I can confirm by now that usage of <UseMauiEssentials>true</UseMauiEssentials> has no bearing on the issue (I recall it clashing with Xamarin.Essentials being a potential cause though).

I am using plain .NET-iOS/.NET-Android with Uno Platform on top, with independent project heads as mentioned above. hence using the plain Sentry.Xamarin seemed as the obvious solution.

Interestingly enough, the exception does not occurr on the Android simulator (haven't tested physical devices yet). ~Though I haven't received a record fromSentrySdk.CaptureMessage yet~.

bruno-garcia commented 2 months ago

The problem here is mixing Xamarin with new, .NET mobile stuff.

net8.0-xyz isn't supported by Xamarin. Xamarin still (and will only, since it's out of support already) target monoandroid11.0 and such TFMs, as we do in this package:

https://github.com/getsentry/sentry-xamarin/blob/efc647fd2d7cd8e3841532cbaf1c1cd77ca9d6ca/Src/Sentry.Xamarin/Sentry.Xamarin.csproj#L6

Xamarin.Essentials.NotImplementedInReferenceAssemblyException this exception is telling me a package is being pulled for net8.0 for example, where only reference assembly exists (no code), and then building an app for a TFM that it doesn't have a proper DLL for. So for example you're building an app for monoandroid11.0 but the NuGet package only has net8.0-android with actual code. SInce that's the new MAUI Essentials stuff.

I recommend keeping the Xamarin apps out of any new msbuild-style csproj or MAUI references. Sentry's Xamarin SDK is still compatible with Xamarin, but you'll have issues with Xamarin if you start trying to mix with new .NET 8 dependencies.

I am using plain .NET-iOS/.NET-Android with Uno Platform on top, with independent project heads as mentioned above. hence using the plain Sentry.Xamarin seemed as the obvious solution.

Sentry itself Sentry core package does have targets for net8.0-ios etc btw. If you're not building a Xamarin app, but just a native mobile app with .NET using net8.0-android, net8.0-ios etc, you don't need this Sentry.Xamarin package. You can use Sentry which targets these native TFMs and includes our native SDKs.

https://www.nuget.org/packages/Sentry#supportedframeworks-body-tab

abenadar commented 2 months ago

@bruno-garcia Thank you, I think using the regular Sentry package indeed brought us on the right track. I will make sure everything works as expected now on every platrform and close the issue/get back to you as soon as I have news.

bruno-garcia commented 1 month ago

Feel free to reopen or open a new ticket if there are issues