-
Notifications
You must be signed in to change notification settings - Fork 53
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
[Java.Interop] suppress IL3050 with #pragma
#1201
Conversation
Context: dotnet/android#8758 (comment) Context: dotnet#1192 In 7d1e705 and b8f6f88, we suppressed IL3050, an AOT-related warning with: // FIXME: dotnet#1192 [UnconditionalSuppressMessage ("AOT", "IL3050")] // Problematic code here We don't immediately *plan* to support NativeAOT on Android in .NET 9, so it would be nice if we could suppress the warning *for now*. But if anyone tried to use this code in a NativeAOT context, they could get a warning. So instead we should use: // FIXME: dotnet#1192 #pragma warning disable IL3050 // Problematic code here #pragma warning restore IL3050 This will prevent us from introducing new `IL3050` and related warnings, but if anyone consumes `Java.Interop.dll` from NativeAOT -- they will see the warning.
One the one hand, this "works"; the build for
On the other hand, I'm not quite sure how to fix these warnings? |
I think the way to fix would be to "generate code", such that you'd perform the same calls without System.Reflection. That would be a lot of work for some of these... I was playing with trimming issues like this here: |
Change: dotnet/java-interop@3436a30...5bca8ad * dotnet/java-interop@5bca8ad6: [build] Automatically add NullableAttributes.cs for netstandard2.0 (dotnet/java-interop#1188) * dotnet/java-interop@45437e22: [Java.Interop] suppress IL3050 with `#pragma` (dotnet/java-interop#1201) * dotnet/java-interop@1c9c8c9c: [Java.Interop.Tools.Maven] Initial commit. (dotnet/java-interop#1179) With dotnet/java-interop@5bca8ad6, all instances of nullable attributes types defined in `NullableAttributes.cs` are now `internal`. However, `Xamarin.Android.Build.Tasks` was consuming the `public` types from its reference to `Java.Interop.Tools.JavaCallableWrappers`, so this change resulted in a build break: MavenExtensions.cs(26,32): error CS0122: 'NotNullWhenAttribute' is inaccessible due to its protection level MamJsonParser.cs(92,43): error CS0122: 'NotNullWhenAttribute' is inaccessible due to its protection level MamJsonParser.cs(92,81): error CS0122: 'NotNullWhenAttribute' is inaccessible due to its protection level We can apply almost the same logic from dotnet/java-interop@5bca8ad6 to `xamarin-android`; the difference is that neither of the `netstandard2.0` projects in xamarin-android that need the attributes have `$(Nullable)='enabled'` and thus our `Condition` fails. (`Xamarin.Android.Build.Tasks.csproj` and `Xamarin.Android.Tools.JavadocImporter.csproj` include `.cs` files from `external/Java.Interop` that have been NRT annotated and thus need the nullable attribute types.) We add `$(Nullable)='annotations'` to the `@(Compile)` which allows one to use NRT syntax but does not emit any NRT warnings since these assemblies have not been converted. We then modify the `NullableAttributes.cs` inclusion logic to additionally key off the `$(Nullable)=annotations` value. Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jonathan Pobst <jonathan.pobst@microsoft.com>
Context: dotnet/android#8758 (comment)
Context: #1192
In 7d1e705 and b8f6f88, we suppressed IL3050, an AOT-related warning with:
We don't immediately plan to support NativeAOT on Android in .NET 9, so it would be nice if we could suppress the warning for now. But if anyone tried to use this code in a NativeAOT context, they could get a warning.
So instead we should use:
This will prevent us from introducing new
IL3050
and related warnings, but if anyone consumesJava.Interop.dll
from NativeAOT -- they will see the warning.