dotnet / dotnet/android-libraries

`Xamarin.Jetbrains.Annotations` namespace clash with `JetBrains.Annotations` causes CS0433 build failure

Open
#885 1 comment 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
C#
Stars
317
Forks
73
Avg merge
1d 8h
Merged PRs (30d)
17

Description

### Android application type

Android for .NET (net6.0-android, etc.)

### Affected platform version

MSBuild version 17.9.8+b34f75857 for .NET 8.0.204

### Description

First noticed in https://github.com/ppy/osu/pull/27179/commits/9c22fa3a9fbae0fb568e5a7b36d4c688268add3a.

The java binding for `org.jetbrains.annotations` (named [Xamarin.Jetbrains.Annotations](https://www.nuget.org/packages/Xamarin.Jetbrains.Annotations)) uses the `Jetbrains.Annotations` namespace. This directly clashes with the .NET [JetBrains.Annotations](https://www.nuget.org/packages/JetBrains.Annotations) which also uses the `Jetbrains.Annotations` namespace.

This namespace clash is apparent when using a type that is defined in both the [Java](https://javadoc.io/doc/org.jetbrains/annotations/latest/org/jetbrains/annotations/package-summary.html) and in the [.NET](https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html#NotNullAttribute) version of the library. For example, `NotNullAttribute`.

Offending line that produces the clashing namespace:

https://github.com/xamarin/AndroidX/blob/3c8325e40f151719f5d3e5a3c34baa56b0b88bb5/Directory.Build.props#L74

As for fixing this issue, I suggest you change the namespace for the java binding. I don't think the types from the java library are meant to be used in application code, so the name of the namespace probably doesn't matter.

### Steps to Reproduce

1. Create a new android library or application project
2. Add [JetBrains.Annotations] and [Xamarin.Jetbrains.Annotations] (or a package that depends on it, like [Xamarin.AndroidX.Window]) nuget package references
```csproj


```
3. Try to use `JetBrains.Annotations.NotNullAttribute`
```cs
using JetBrains.Annotations;

namespace AndroidLib1;

public class Class1
{
public void Test([NotNull] object obj)
{
}
}
```
4. Try to build the project, the build will fail with error
```cs
error CS0433: The type 'NotNullAttribute' exists in both 'JetBrains.Annotations, Version=4242.42.42.42, Culture=neutral, PublicKeyToken=1010a0d8d6380325'
and 'Xamarin.Jetbrains.Annotations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
```

[JetBrains.Annotations]: https://www.nuget.org/packages/JetBrains.Annotations
[Xamarin.Jetbrains.Annotations]: https://www.nuget.org/packages/Xamarin.Jetbrains.Annotations
[Xamarin.AndroidX.Window]: https://www.nuget.org/packages/Xamarin.AndroidX.Window

### Did you find any workaround?

Add this to the project. Taken from https://stackoverflow.com/questions/9194495/type-exists-in-2-assemblies/65127159#65127159.

```csproj




XamarinJetbrainsAnnotations


```

### Relevant log output

```shell
❯ dotnet build AndroidLib1
MSBuild version 17.9.8+b34f75857 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
S:\code\TestConsoleApp1\AndroidLib1\Class1.cs(7,23): error CS0433: The type 'NotNullAttribute' exists in both 'JetBrains.Annotations, Version=4242.42.42.42, Culture=neutral, PublicKeyToken=1010a0d8d6380325' and 'Xamarin.Jetbrai
ns.Annotations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' [S:\code\TestConsoleApp1\AndroidLib1\AndroidLib1.csproj]

Build FAILED.

S:\code\TestConsoleApp1\AndroidLib1\Class1.cs(7,23): error CS0433: The type 'NotNullAttribute' exists in both 'JetBrains.Annotations, Version=4242.42.42.42, Culture=neutral, PublicKeyToken=1010a0d8d6380325' and 'Xamarin.Jetbrai
ns.Annotations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' [S:\code\TestConsoleApp1\AndroidLib1\AndroidLib1.csproj]
0 Warning(s)
1 Error(s)

Time Elapsed 00:00:01.45
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.