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

Open abenadar opened 3 months ago

abenadar commented 3 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 2 months ago

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

abenadar commented 2 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 2 months ago

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

lucas-zimerman commented 2 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 2 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~.