Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingMethodException throws when Capture any event #72

Closed
huyvuskedulo opened this issue Jun 3, 2021 · 18 comments
Closed

MissingMethodException throws when Capture any event #72

huyvuskedulo opened this issue Jun 3, 2021 · 18 comments

Comments

@huyvuskedulo
Copy link

huyvuskedulo commented Jun 3, 2021

Any ideas why this is happening? If i tried sentry on a completely new app, it's not an issue, but when i used it in my app , this is what happened when trying to send a message

Environment

Which SDK and version?
Sentry.Xamarin 1.0.3
Refit 5.2.4 (i don't know if this is related but this package have a reference to System.Text.Json as well)

Steps to Reproduce

Just Init in my app and attempt to send a message

Expected Result

Should not throw this excpetion

Actual Result

Error: Failed to send cached envelope: System.MissingMethodException: Method not found: System.Text.Json.JsonDocument System.Text.Json.JsonDocument.Parse(System.ReadOnlyMemory`1,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:152
at Sentry.Protocol.Envelopes.Envelope.DeserializeAsync (System.IO.Stream stream, System.Threading.CancellationToken cancellationToken) [0x00032] in /
/src/Sentry/Envelopes/Envelope.cs:164
at Sentry.Internal.Http.CachingTransport.ProcessCacheAsync (System.Threading.CancellationToken cancellationToken) [0x00117] in /_/src/Sentry/Internal/Http/CachingTransport.cs:173 , discarding cached envelope.

@bruno-garcia
Copy link
Member

Sounds like you have a consistent repro if you can just Init and send an event.

Would it be possible to strip stuff off of your app (or somehow make it into a repro you can share with us?).
That would really help us debug this.

@huyvuskedulo
Copy link
Author

I will try to make a repo to share with you guys.

The problem is our current app is having a lot of dependencies, so i will try to make a new project to see if we can reproduce it.

@huyvuskedulo
Copy link
Author

@bruno-garcia

Good news is i can reproduce this by cloning my project dependency into a more simple project.

Here is the link for the project.

https://github.com/unamed000/my-cat-demo/tree/sentry-error

(I cloned the dependency for the main PCL project and iOS, so you might need to test it on ios)

When you click on a cat in the list view, an error will be printed out like the one i reported

@huyvuskedulo
Copy link
Author

Turn out, this is a bug from Akavache, i've linked the issue from Akavache to this one. I think Akavache is using the old System.Text.Json somehow.

@huyvuskedulo
Copy link
Author

huyvuskedulo commented Jun 9, 2021

ericsink/SQLitePCL.raw#422

After further investigation, we can see this package is conflicting with SQLitePCL.raw package, not Akavache (Akvache is using a dependency to this package).

We still don't know why when using SQLitePCL.raw, the wrong System.Text.JSON is used in Sentry package? So any ideas or suggestions to fix this will be really helpful for us to make sentry works in our app. (Because in Xamarin, a lot of people are using sqlite packages) @bruno-garcia

@huyvuskedulo huyvuskedulo reopened this Jun 9, 2021
@merckxite
Copy link

We're experiencing exactly the same issue. Seems to have started happening when we migrated our apps onto the iOS14 API's (and in turn newer versions of Visual Studio for Mac, .Net SDK, Mono and Xamarin.iOS). We have none of the dependencies cited above as possible conflicts. Our Xamarin.Android project is fine.

Seems like this issue with System.Text.Json is happening elsewhere also https://docs.microsoft.com/en-us/answers/questions/302548/jsonserializer-throws-exception-in-xamarinios.html

We can consistently repro this in the latest version of VS for Mac:

Visual Studio 2019 for Mac: 8.10.1
Mono Framework MDK: 6.12.0.140
.NET Core SDK: 5.0.301
Xcode: 12.5
Xamarin.iOS: 14.20.0.3

Would also love to know if anyone has a workaround as this is affecting our ability to monitor errors in production.

@bruno-garcia
Copy link
Member

As @lucas-zimerman identified, this issue is discussed on the mono repository: mono/mono#20805

The work around is to add these dependencies directly to the app:

    <PackageReference Include="System.Memory" Version="4.5.4" />
    <PackageReference Include="System.Buffers" Version="4.5.1" />

We'll add this to the docs and possibly to the Xamarin SDK directly.

@huyvuskedulo
Copy link
Author

@bruno-garcia

Adding these 2 dependencies is not solving the issues for me, the error is still there.

I think this dependency error is a little different than the one in the above link.

@bruno-garcia
Copy link
Member

@huyvuskedulo do you already specify System.Text.Json version 5.0.0 directly on your project?

@huyvuskedulo
Copy link
Author

@bruno-garcia Yes i did, actually that was the first thing i tried to do, you can try my repo above, and you will be able to reproduce it immediately

@bruno-garcia
Copy link
Member

Thanks for the repro. We'll take a look at it

@huyvuskedulo
Copy link
Author

Thanks @bruno-garcia , let me know if you can find out anything :D

@lucas-zimerman
Copy link
Collaborator

lucas-zimerman commented Jun 18, 2021

I'll give a look at it : )

as a workaround, you could try disabling the cache to your Sentry options:

            SentryXamarin.Init(ops => {
                ops.Debug = true;
                ops.Dsn = "...";
                ops.AddXamarinFormsIntegration();
                ops.DisableOfflineCaching();
            });

This will disable the log of events/errors offline but also may lead to not registering unhandled exceptions...

We'll keep investigating this issue :)

@huyvuskedulo
Copy link
Author

Hi @lucas-zimerman .

Thanks for the workaround, but since offline mode and registering unhandled exceptions are vital in our apps, so we can't ignore that :).

We're having a plan for migrating into Sentry, but until these issues are fixed, we can't do it yet.

@lucas-zimerman
Copy link
Collaborator

Hi @huyvuskedulo .

After further investigation, I was able to conclude tha this is a mono issue related to mono/mono#20805 and not with the SDK

You can also validate it by adding the following code anywhere into your iOS project:
var x = new byte[2].AsMemory();
You'll notice that you'll get the following error message
image
that happens because mono implements the extension AsMemory and other nuget (like the SqlLite one) also uses the System.Memory, causing the conflict.

Workaround

To solve this, you'll need to unload your iOS project,
image
Edit or replace the System.Memory reference by:

    <PackageReference Include="System.Memory" IncludeAssets="None">
      <Version>4.5.4</Version>
    </PackageReference>

Note: the parameter IncludeAssets="None" is required otherwise it'll not work.
image

After that, you'll need to reload your project AND Exit your solution (this is silly but Visual Studio will only apply the changes after you restart it)
image

Finally, after a while (took me a minute after the IDE sorted the packages references), you'll notice that the conflict will be sorted out and Sentry will stop throwing the mentioned error in this PR.
image

@huyvuskedulo
Copy link
Author

Thanks @lucas-zimerman , the workaround works for me

@bruno-garcia
Copy link
Member

Worth adding to the docs under Troubleshooting

@bruno-garcia
Copy link
Member

bruno-garcia commented Aug 31, 2021

The findings from this thread are not on the troubleshooting page. Please let us know if anything else comes up:

https://docs.sentry.io/platforms/dotnet/guides/xamarin/troubleshooting/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants