However when I click Publish I am getting the following KeyNotFound Exception.

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
at Xamarin.VisualStudio.Android.Utilities.BuildProject(Project project, String target, IVsOutputWindowPane outputPane, Exception& ex)

Posts

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
at Xamarin.VisualStudio.Android.Utilities.BuildProject(Project project, String target, IVsOutputWindowPane outputPane, Exception& ex)

Surely someone else must have had this same issue. I can not for the life of me get this to work. I am trying to publish my app to google play but can not get this signing step to work at all. Please please please can anyone help me?

I am doing this from Visual Studio, not Xamarin Studio. I have other issues with Xamarin Studio which I also need to resolve. I have tried alsorts or things, including moving to a competely different Windows VM. Interestingly I now get this exception:

So, wanting to have LLVM turned on I decided to resolve all my Xamarin Studio issues, of which there were many (I will not go into that). But I got everything working sweet on XS regarding builds etc. So, I decide to try the XS route and select 'Archive for Publishing' with LLVM turned on. I was hopeful. Alas, I get the following error:

(Thanks for the heads-up on this forum thread via the "Business & Enterprise Support" email channel. Emails to the support team and bug reports are the best way to ensure that potential bugs are seen by the Xamarin engineering teams.)

Ah ha! It looks like both of these are actually AOT build errors rather than signing issues. The "KeyNotFound" exception name is just a horribly unfortunate coincidence because the exception happens when attempting to access a C# dictionary key. In theory you would see these same errors even when using the debug keystore, for example if you attempted to deploy to device or emulator using the same build configuration that you're using for publishing. (You could also hit the same error just by building the project if you switched DefaultTargets="Build" to DefaultTargets="SignAndroidPackage" by editing the text of the .csproj file. See also "Xamarin.Android Build Targets.")

The original error from the first post in the thread looks like it could be a bug in AOT/LLVM support that would be specific to your project. If by chance you might be able to provide a test case that demonstrates that problem, the Xamarin.Android team would be interested to work on it. AOT and LLVM support is still "experimental" for Android, so any new failing edge cases that can be provided to the engineering team are much appreciated. You can use this pre-formatted bug link so you only have to worry about the "Summary" and "Description", and then you can attach your test case and a brief description of the steps to reproduce. Thanks in advance! (Side note: there's also a chance the issue might be resolved in the current Cycle 6 "Release Candidate" that is currently available on the Alpha updater channel, in case you might like to experiment with that.)

For the new error in Xamarin Studio, the error message is a bit more informative:

The AOT feature requires being able to use the cross-compilers and Android-API-level-specific native libraries that are shipped as part of the Android NDK. It sounds like the "r10d" release of the NDK cross-compiler toolchain does not include the libraries for API Level 23. You can check the android-ndk-r10d/platforms/ folder to see which platforms are supported by that NDK, and switch your application to target one of those.

A small additional follow-up: the Cycle 6 "Release Candidate" includes some extra logic that allows Android API 23 projects to be AOT-compiled using the android-21 platform from the "r10d" NDK toolchain. That should in theory stop the error message for this particular pairing of versions.

In the end I have just turn off LLVM and it works. I don't really have time, or afford the risk, of trying C6 RC Alpha as this is an App Store release. Btw, is LLVM likely to improvement the running performance at all as some aspects of my app are sluggish on Android?