sentry-xamarin icon indicating copy to clipboard operation
sentry-xamarin copied to clipboard

'Xamarin.Essentials.NotImplementedInReferenceAssemblyException' despite direct reference

Open abenadar opened this issue 1 year ago • 5 comments

Environment

I have three seperate projects each targeting a different platform.

  • net8.0-iOS
  • net8.0-android
  • net8.0-windows10.0.19041.0 w/ WindowsAppSDK 1.5.240311000

<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.

abenadar avatar Apr 08 '24 09:04 abenadar

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

kkabala avatar Apr 19 '24 14:04 kkabala

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.

abenadar avatar Apr 22 '24 07:04 abenadar

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

bitsandfoxes avatar Apr 23 '24 14:04 bitsandfoxes

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.

lucas-zimerman avatar Apr 23 '24 16:04 lucas-zimerman

@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 from SentrySdk.CaptureMessage yet~.

marwalsch avatar Apr 24 '24 09:04 marwalsch

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

bruno-garcia avatar Aug 19 '24 14:08 bruno-garcia

@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.

abenadar avatar Aug 30 '24 11:08 abenadar

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

bruno-garcia avatar Oct 06 '24 03:10 bruno-garcia