[Mono.Android] Compile RuntimeFeature into a single assembly to avoid conflict warnings#11669
Open
simonrozsival wants to merge 1 commit into
Open
[Mono.Android] Compile RuntimeFeature into a single assembly to avoid conflict warnings#11669simonrozsival wants to merge 1 commit into
simonrozsival wants to merge 1 commit into
Conversation
`Microsoft.Android.Runtime.RuntimeFeature` was compiled into both
`Mono.Android.Runtime.dll` and `Mono.Android.dll`. Because `Mono.Android`
references `Mono.Android.Runtime` (which exposes its internals to
`Mono.Android` via `InternalsVisibleTo`), building `Mono.Android.dll`
emitted 58 `CS0436` warnings:
warning CS0436: The type 'RuntimeFeature' in
'src/Mono.Android/Microsoft.Android.Runtime/RuntimeFeature.cs' conflicts
with the imported type 'RuntimeFeature' in 'Mono.Android.Runtime'.
Compile `RuntimeFeature.cs` only into `Mono.Android.Runtime.dll` (the
lower-level assembly that already owns it) and let the other assemblies use
it through `InternalsVisibleTo`:
* Remove the duplicate `<Compile Include="...RuntimeFeature.cs" />` from
`Mono.Android.csproj`.
* Grant `Mono.Android.Runtime` internals to
`Microsoft.Android.Runtime.NativeAOT` and `Mono.Android.NET-Tests`, which
previously accessed `RuntimeFeature` through `Mono.Android.dll`.
* Once `RuntimeFeature` is only imported (no longer source-compiled) into
`Mono.Android`, the unqualified name `RuntimeFeature` becomes ambiguous
with `System.Runtime.CompilerServices.RuntimeFeature`. Add
`using RuntimeFeature = Microsoft.Android.Runtime.RuntimeFeature;` to the
three affected files, matching the alias already used in `JNIEnvInit.cs`.
`Microsoft.Android.Runtime.RuntimeFeature` is now defined in exactly one
assembly (`Mono.Android.Runtime.dll`), and the 58 `CS0436` warnings are gone.
This is a focused subset of #11625 that addresses only the `RuntimeFeature`
duplication, without that PR's class rename or unrelated warning cleanups.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes the duplicate compilation of Microsoft.Android.Runtime.RuntimeFeature into Mono.Android.dll, ensuring it is defined only in Mono.Android.Runtime.dll to eliminate CS0436 type-conflict warnings and avoid CS0104 ambiguity with System.Runtime.CompilerServices.RuntimeFeature.
Changes:
- Stop compiling
Microsoft.Android.Runtime/RuntimeFeature.csintoMono.Android.dll(leaving it only inMono.Android.Runtime.dll). - Add
InternalsVisibleToentries inMono.Android.RuntimeforMicrosoft.Android.Runtime.NativeAOTandMono.Android.NET-Tests. - Disambiguate
RuntimeFeatureusage viausing RuntimeFeature = Microsoft.Android.Runtime.RuntimeFeature;in the affected source files.
Show a summary per file
| File | Description |
|---|---|
| src/Mono.Android/Mono.Android.csproj | Removes duplicate Compile entry for RuntimeFeature.cs to prevent cross-assembly type conflicts. |
| src/Mono.Android/Java.Interop/TypeManager.cs | Adds RuntimeFeature type alias to avoid CS0104 ambiguity. |
| src/Mono.Android/Android.Runtime/JNIEnv.cs | Adds RuntimeFeature type alias to avoid CS0104 ambiguity (while still using BCL RuntimeFeature fully-qualified). |
| src/Mono.Android/Android.Runtime/AndroidRuntime.cs | Adds RuntimeFeature type alias to avoid CS0104 ambiguity. |
| src/Mono.Android.Runtime/Properties/AssemblyInfo.cs.in | Grants internals access to NativeAOT and test assemblies now that RuntimeFeature is owned by Mono.Android.Runtime. |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 0
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Microsoft.Android.Runtime.RuntimeFeaturewas compiled into two assemblies:Mono.Android.Runtime.dll(src/Mono.Android.Runtime/Mono.Android.Runtime.csproj)Mono.Android.dll(src/Mono.Android/Mono.Android.csproj)Because
Mono.AndroidreferencesMono.Android.Runtime(which exposes its internals viaInternalsVisibleTo), compilingMono.Android.dllemitted 58CS0436warnings:This PR makes
RuntimeFeaturelive in exactly one assembly.Changes
Mono.Android.csproj— remove the duplicate<Compile>ofRuntimeFeature.cs, so it is compiled only intoMono.Android.Runtime.dll(the lower-level assembly that already owns it).Mono.Android.Runtime/Properties/AssemblyInfo.cs.in— grant internals toMicrosoft.Android.Runtime.NativeAOT(JreRuntime.cs) andMono.Android.NET-Tests(test sources), which previously reachedRuntimeFeaturethroughMono.Android.dll.AndroidRuntime.cs,JNIEnv.cs,TypeManager.cs— addusing RuntimeFeature = Microsoft.Android.Runtime.RuntimeFeature;. OnceRuntimeFeatureis only imported, the unqualified name becomes ambiguous withSystem.Runtime.CompilerServices.RuntimeFeature(CS0104). The alias disambiguates it, matching the alias already used inJNIEnvInit.cs.Relationship to #11625
This is a focused subset of #11625, addressing only the
RuntimeFeatureduplication. It intentionally drops that PR's class rename (RuntimeFeature→AndroidRuntimeFeature) and the unrelated warning cleanups. (TheCS0104ambiguity above is exactly why #11625 renamed the type; here it is resolved with theusingalias instead.)Verification
Building
Mono.Android+Microsoft.Android.Runtime.NativeAOT:Metadata check (
monodis --typedef) —Microsoft.Android.Runtime.RuntimeFeatureis now defined in only one assembly:RuntimeFeatureMono.Android.dllMono.Android.Runtime.dllMicrosoft.Android.Runtime.NativeAOT.dll