getsentry / sentry-xamarin

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

[BUG] Android caching not working #98

Closed Hugo-Persson closed 2 years ago

Hugo-Persson commented 2 years ago

Environment

How do you use Sentry? sentry.io

Which SDK and version? Sentry.Xamarin.Forms 1.3.1

Steps to Reproduce

  1. I threw an null exception in MainActivity.cs
  2. I reported the exception to Sentry with SentrySdk.CaptureException(e);

Expected Result

I expected the exception to be reported to Sentry.

Actual Result

The exception was not reported and when I checked the logs it said

Error: Failed to send cached envelope: /data/user/0/se.recruto.app/files/.local/share/Sentry/02A6EA804EEE9F2AB1F3BD97BAB66F72272DC6B4/__processing/1641814777_9932__-1903654489.envelope, discarding cached envelope.
System.MissingMethodException: Method not found: System.Text.Json.JsonDocument System.Text.Json.JsonDocument.Parse(System.ReadOnlyMemory`1<byte>,System.Text.Json.JsonDocumentOptions)
  at Sentry.Protocol.Envelopes.Envelope.DeserializeHeaderAsync (System.IO.Stream stream, System.Threading.CancellationToken cancellationToken) [0x001a1] in /_/src/Sentry/Envelopes/Envelope.cs:186 
  at Sentry.Protocol.Envelopes.Envelope.DeserializeAsync (System.IO.Stream stream, System.Threading.CancellationToken cancellationToken) [0x00032] in /_/src/Sentry/Envelopes/Envelope.cs:198 
  at Sentry.Internal.Http.CachingTransport.ProcessCacheAsync (System.Threading.CancellationToken cancellationToken) [0x00111] in /_/src/Sentry/Internal/Http/CachingTransport.cs:163 
  at Sentry.Internal.Http.CachingTransport.ProcessCacheAsync (System.Threading.CancellationToken cancellationToken) [0x002cd] in /_/src/Sentry/Internal/Http/CachingTransport.cs:172   Debug: No cached file to process.
  Debug: Registering integration: 'AutoSessionTrackingIntegration'.
  Debug: Attempting to recover persisted session from file.
  Debug: A persisted session does not exist at /data/user/0/se.recruto.app/files/.local/share/Sentry/02A6EA804EEE9F2AB1F3BD97BAB66F72272DC6B4/.session.
  Debug: Created directory for installation ID file (/data/user/0/se.recruto.app/files/.local/share/Sentry/02A6EA804EEE9F2AB1F3BD97BAB66F72272DC6B4).
  Debug: Resolved installation ID '0c23f0cd-ccac-4536-bcbb-d2a136c08785'.
   Info: Started new session (SID: c71750ea3c184978949e5ccccdef11cb; DID: 0c23f0cd-ccac-4536-bcbb-d2a136c08785).

If I add the options.DisableOfflineCaching(); in the init it works. This article https://docs.sentry.io/platforms/dotnet/guides/xamarin/troubleshooting/ explains how to fix it on iOS but not on Android.

lucas-zimerman commented 2 years ago

Hi Hugo, Would you mind sharing the NuGet packages that you're using and their versions?

Additionally, what happens if you add the following code on your main activity?

    _ = new byte[2].AsMemory();
Hugo-Persson commented 2 years ago

When I add the line no error is generated and it is referring to

public static Memory AsMemory(this T[] array) => new Memory(array); in public static partial class MemoryExtensions

I am using this sentry NuGet packages

<PackageReference Include="Sentry.Xamarin.Forms">
      <Version>1.3.1</Version>
    </PackageReference>
lucas-zimerman commented 2 years ago

I see. Which version of Xamarin Forms are you using and are you running it with linker? Additionally, could you try to add the NuGet package System.Text.Json and see if the problem fades away?

If possible, could you upload a small repro project containing the problem? That would help us a lot to investigate the problem.

Hugo-Persson commented 2 years ago

I solved this issue by updating my project from using Portable Class Libraries to .NET Standard