Closed khalilyamoun closed 2 years ago
A sharing violation would indicate that more than one thread is trying to access the same file simultaneously, which would be quite strange indeed.
I've not seen any other reports of this, neither with Xamarin nor any other .NET project types.
When you say "Init should be re-called" - this should only happen if you're actually entering the onCreate
stage again - which should only happen if the app was completely terminated the first time.
From the Android docs here:
Sentry should be initialized in onCreate
(of the main activity), not in onStart
, onResume
, onRestart
or the onCreate
of an activity other than the main one for the app.
I do see SplashActivity.OnCreate
in your call stack, but I'm not sure whether that's the main activity of your application (such as MainActivity
we show in our readme), or if that's being launched from somewhere else. Perhaps you are launching your splash screen from onRestart
? Can you clarify, and perhaps put a more complete example together?
Thanks.
@lucas-zimerman - Are you available to help investigate? Thanks.
@lucas-zimerman - Are you available to help investigate? Thanks.
Sure. But here are a few questions in advance.
One assumption that I have is that the app is partially restarted (the Android activity is restarted but the .NET code stays unchanged)
Ideally the SDK shouldn't crash the app when SentryXamarin.Init is invoked but I'll investigate what could be causing this issue.
@mattjohnsonpint @lucas-zimerman - Here's what's happening.
Keep in mind that :
@mattjohnsonpint, when you say "I've not seen any other reports of this, neither with Xamarin nor any other .NET project types."
Thanks for the detailed response. I'm glad you found a workaround, but I'd still like to get this resolved fully.
It does sound like you're initializing Sentry when it is already initialized. Ideally you'd only be initializing once.
One quick test you can do is to check SentrySdk.IsEnabled
, such as:
if (!SentrySdk.IsEnabled)
{
SentryXamarin.Init(... your init options ...);
}
This won't hurt, but it shouldn't be required, as we detect and handle such a condition internally.
You say that it started after updating to Sentry.Xamarin 1.4.3. Can you please tell me which version you ran before that? When did it last work?
Thanks.
I did a bit more investigation, and indeed if Sentry is initialized twice with caching enabled, there is a potential for conflict on the cache files. This could manifest as a sharing violation on Android. See https://github.com/getsentry/sentry-dotnet/issues/2033 for more details.
We'll leave this open for Sentry.Xamarin and re-visit after resolving that.
Thanks.
Environment
Xamarin.Android Sentry-Xamarin : 1.4.3 Sentry-dotnet : 3.23.1
Steps to Reproduce
Expected Result
App should restart normally.
Actual Result