[Java.Interop] suppress IL3050 with #pragma#1201
Merged
jonpryor merged 1 commit intodotnet:mainfrom Mar 11, 2024
Merged
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.
Contributor
|
One the one hand, this "works"; the build for On the other hand, I'm not quite sure how to fix these warnings? |
Member
Author
|
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: |
jonpryor
pushed a commit
to dotnet/android
that referenced
this pull request
Mar 13, 2024
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
IL3050and related warnings, but if anyone consumesJava.Interop.dllfrom NativeAOT -- they will see the warning.