XA0105 should be an error, not an warning
- Dominant language
- C#
- Stars
- 2.1k
- Forks
- 579
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 257
Description
Context: https://github.com/xamarin/xamarin-android/pull/6328#issuecomment-930339362
Context: https://github.com/xamarin/xamarin-android/pull/6328#issuecomment-931304788
### Steps to Reproduce
Build and run the following app: [Scratch.xa0105.zip](https://github.com/xamarin/xamarin-android/files/7263282/Scratch.xa0105.zip)
### Expected Behavior
"It runs" and/or it *doesn't* build. (The latter is easier to achieve.)
### Actual Behavior
`TypeLoadException` at runtime:
```
android.runtime.JavaProxyThrowable: System.TypeLoadException: Could not load type of field 'Library.Class1:p' (0) due to: Could not resolve type with token 01000011 from typeref (expected class 'Android.Util.Proto.ProtoOutputStream' in assembly 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065') assembly:Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065 type:Android.Util.Proto.ProtoOutputStream member:(null)
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in :0
```
### Version Information
Happens with Xamarin.Android 12.0.0 via xamarin/xamarin-android/d16-11@25821c6 (so, lol? version doesn't really matter though. All current "Xammie" versions!)
### Discussion
[Warning XA0105](https://github.com/xamarin/xamarin-android/blob/af60da7f13e613faa8ded5ef734e8c6d91445acc/Documentation/guides/messages/xa0105.md) is emitted when the App assembly has a `$(TargetFrameworkVersion)` which is lower than that of a referenced assembly.
A warning is better than nothing, but not everybody reads or fixes warnings.
Thus, the repro:
* `Library.dll` has a `$(TargetFrameworkVersion)`=v11.0, and uses [`ProtoOutputStream`](https://developer.android.com/reference/android/util/proto/ProtoOutputStream), introduced in API-30.
* `App.dll` has a `$(TargetFrameworkVersion)`=v9.0, and references `Library.dll`.
This is exactly the scenario that XA0105 checks for.
The problem is that this can't possibly work at runtime: *currently*, the `Mono.Android.dll` included in the `.apk` is based on the `$(TargetFrameworkVersion)` of the *App*, i.e. v9.0. The v9.0 `Mono.Android.dll` can't possibly have types specific to the v11.0 `Mono.Android.dll`. Consequently, if/when `App.dll` attempts to use an "inappropriate" type from `Library.dll`, a `TypeLoadException` is thrown.
There are two "plausibly sane" fixes:
1. When this scenario is detected, we *override* the `Mono.Android.dll` included in the `.apk`/Fast Deployment to be that of the *highest detected* `$(TargetFrameworkVersion)`, i.e. v11.0 in this case. *-or-*
2. We turn XA0105 into an *error*, and require that this scenario be fixed.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.