Large number of Visual Studio Warning CA1416 targeting Android with MonoGame 3.8.1


I am updating a solution from MonoGame 3.8.0 to 3.8.1 that contains projects for multiple platforms (Android, iOS, Windows PC, UWP). The bulk of the code is contained in a C# shared project, and just the platform specific code is contained in each of the platform specific projects.

After upgrading MonoGame, everything compiled fine and worked on the emulator. However, I am getting about 1,500 CA1416 warnings, see sample below. The warning is called by lines of code containing MonoGame calls to everything from Vector2, to Song, to SpriteBatch. The warnings are occurring in both the shared code library and the Android specific project.

Sample of the Warning

Warning CA1416 This call site is reachable on: ‘Android’ 26.0 and later. ‘Vector2.X’ is only supported on: ‘Android’ 31.0 and later.
Using platform dependent API on a component makes the code no longer work across all platforms.

Setting the minimum Android API to 31 clears the warning, as would be expected. However, API 31 is super new and I’m assuming you would not want this for your minimum target version as it would exclude the bulk of devices?

I have never seen this warning below, but I think it is trying to warn me that the code should not work when running on a device below API 31? However, Leaving the minimum API below 31 still compiles and works fine on an emulator set below API 31.

Was wondering if maybe I am interpreting this warning incorrectly, or if this is some sort of false hit on the warning by MonoGame? Or perhaps I am using the language incorrectly?

Any assistance would be appreciated.

Thank you.

Looks like this already written up as an issue on the MonoGame GitHub page here: Warning CA1416 when buildig for Android · Issue #7896 · MonoGame/MonoGame · GitHub

yeah, I’m having the same issue. It happens even on an empty Android project you create with the extension.
Not sure if I should go back to 3.8.0


Something interesting I noticed is that I get that error but complaining about a different version.

warning CA1416: This call site is reachable on: 'Android' 21.0 and later. 'Vector2.Y' is only supported on: 'Android' 31.0 and later.

Any ideas?

Hi ,
try to install version 31
then in the AndroidManifest.XML

<uses-sdk android:minSdkVersion="31" android:targetSdkVersion="31" />

I hope this solves your problem

It does, but by doing that it leaves out you a bunch of recent devices.
They are taking care of this issue on that link that Brett posted.

the warnings are gone on my BASIC multitarget test rig for a basic clip shader and a shared GAme/ asset module …but i have no idea why or when those warnings went away or what i did., i and im moving on to my other issues with net48 /wpf/hosting MG. I hope it helps someone, AFAIK there are ZERO mg3.81/net60 samples that work, that show the power of Monogame, one codebase, with shaders, that can reach a billion devices, without much #fdefs, switches or even repeated links, or ANY routine maintainance per platfrom. i just dont have time to perfect it the point is i can work on my codebase again… im not going to deploy or release anytime soon or i would not have updated any tooling, but at least my stuff works and im on the latest toolchain even if its in heavy flux. vs 2022 windwos 11 intel, deploy to emulator and to ARM64 failry new samsung androidn 31 phone.

i just got it so i can touch a shared fx file, build and run and see the changes on android, desktiop GL and DX. if anyone wants to review or it try it or simply or correct it, your Welcome. its based on the old samples ut i dont have to link individual assets to each target, just the content.mgcb file.

Wanted to mention this issue is now fixed in the dev branch of MonoGame.

Also, if you don’t want to pull the dev branch, you should be able to use the global suppressions file to suppress the warning in the short term. See below for a sample.

[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "MonoGame incorrectly warns of min target version being set below 31.", Scope = "namespaceanddescendants", Target = "~N:XXX")]


1 Like