Skip to content

Commit 0f3c083

Browse files
Android dotnet package version outside of dependency constraint (#13763)
## DESCRIBE YOUR PR Added docs on troubleshooting "Detected package version outside of dependency constraint" errors. Resolves getsentry/sentry-dotnet#4095 (see [comment](getsentry/sentry-dotnet#4095 (comment))) ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - cc: @Flash0ver ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs)
1 parent 5539a1f commit 0f3c083

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/platforms/dotnet/common/troubleshooting.mdx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,49 @@ will not be sent to Sentry. If Sentry cannot locate symbols, then it cannot perf
2626
This means that for some types of projects (depending on configuration), you may not see filenames and line numbers
2727
to help you locate the source of an exception.
2828

29+
## Detected package version outside of dependency constraint
30+
31+
In .NET for Android applications the Sentry SDK needs to make use of a limited number of Android APIs that form part of the operating system. Implicitly, Sentry depends on [various Java packages](https://github.com/getsentry/sentry-dotnet/blob/ebc1115d6c928ff56244afa3a1ce1d79b078fbf4/src/Sentry.Bindings.Android/Sentry.Bindings.Android.csproj#L45-L56) then.
32+
33+
If you are using third party libraries that depend on different versions of these same Java packages, you may see `NU1605`, `NU1608` and/or `NU1107` warnings when trying to run `dotnet restore`.
34+
35+
Sentry itself only specifies a minimum version of the Java packages that it depends on, so is compatible with any higher versions of the same Java packages. However, these Java packages come with their own dependencies, which are therefore transitive dependencies for Sentry. The transitive dependencies of the Sentry SDK can sometimes be incompatible with the transitive dependencies of other third party libraries and NuGet isn't smart enough to resolve those conflicts without a bit of guidance.
36+
37+
Such problems need to be resolved on a case by case basis but the following example should demonstrate how you can resolve these issues if you run into them in your own application.
38+
39+
### Example Problem
40+
41+
If you use `Sentry` `5.7.0` in a .NET for Android application targeting `net9.0-android` then Sentry will have various [direct dependencies](https://www.nuget.org/packages/Sentry/5.7.0#dependencies-body-tab). However those direct dependencies come with their own dependencies, which for Sentry are transitive dependencies.
42+
43+
If you also use `Microsoft.Maui.Essentials` version `9.0.50`, ultimately it depends on conflicting version of those same transitive dependencies.
44+
45+
In this scenario you would see a warning or an error like the following when running `dotnet restore`:
46+
```
47+
NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.Common.Java8 2.8.5.1 requires Xamarin.AndroidX.Lifecycle.Common (>= 2.8.5.1 && < 2.8.6) but version Xamarin.AndroidX.Lifecycle.Common 2.8.7.2 was resolved.
48+
```
49+
50+
### Example Solution
51+
52+
To resolve the problem above, you can use [Transitive Pinning](https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management#transitive-pinning) to resolve explicit versions of transitive dependencies (rather than letting NuGet resolve these automatically).
53+
54+
To enable Transitive Pinning, add the following to your `csproj` or `Directory.Build.props` file:
55+
56+
```xml
57+
<PropertyGroup>
58+
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
59+
</PropertyGroup>
60+
```
61+
62+
You can then pin the appropriate versions of the transitive dependency that's causing you problems:
63+
64+
```xml
65+
<ItemGroup>
66+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common.Java8" Version="2.8.7.2" />
67+
</ItemGroup>
68+
```
69+
70+
Although the Sentry SDK only needs `Xamarin.AndroidX.Lifecycle.Common.Java8 2.8.5.1`, that version is problematic since it locks the transitive dependency `Xamarin.AndroidX.Lifecycle.Common` into the range `(>= 2.8.5.1 && < 2.8.6)`. By explicitly pinning `Xamarin.AndroidX.Lifecycle.Common.Java8` to `2.8.7.2` to match the version used by `Microsoft.Maui.Essentials`, we can resolve the conflict.
71+
2972
## Updating to 4.12.0 broke my .NET iOS App
3073

3174
Support for Xcode 16.0 was added on version 4.12.0 of the Sentry SDK for .NET

0 commit comments

Comments
 (0)