Forum Xamarin.iOS

The "DetectSigningIdentity" task failed unexpectedly

MattCrombieMattCrombie AUUniversity ✭✭
edited December 2018 in Xamarin.iOS

I've been struggling to get around an issue for the past 2 days around a new distribution certificate and provisioning profile. I've quadruple checked every detail and still haven't been able to get around it and wonder if anyone else has encountered this. This is on Visual Studio for Mac and originally I was on a few versions behind but have tried upgrading to latest since to try and resolve.

I've checked/done all of the following:

  • Bundle name matches provisioning profile app bundle name
  • Regenerated the certificate and profile using distribution and development configurations
  • Created a brand new vanilla project with the bundle name to make sure it wasn't a .csproj or .plist issue
  • Turned on and off push notification configurations because of the reference to aps-environment as well as regenerate the certs
  • Tried all combinations of setting signing identity and profile manually and automatically

The curious thing about this is that if I create a blank project in Xcode and select the cert/provisioning profile it works. It doesn't detect it automatically but importing it does work. It's not detecting it automatically for the Xamarin side of things either but if I enter the following the error appears:

    <CodesignKey>iPhone Distribution: XXXXXX (123456789)</CodesignKey>

The only other thing to note is that there's a few app ID's registered (, com.appname.uat, etc) and this is for a UAT build that has all been working fine until I generated a new distribution certificate and things started failing. I've run this on several machines as part of an Azure DevOps build process, including the Hosted macOS one and none of them work.

The error I'm receiving is:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: The "DetectSigningIdentity" task failed unexpectedly.
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: System.ArgumentException: An item with the same key has already been added. Key: aps-environment

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at System.Collections.Generic.Dictionary2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x002b5] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:677 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at System.Collections.Generic.Dictionary2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:240
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.PDictionary.Add (System.String key, Xamarin.MacDev.PObject value) [0x00001] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.PropertyListFormat+XmlFormat+Context.ReadDict (Xamarin.MacDev.PDictionary dict) [0x000dc] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.PropertyListFormat+ReadWriteContext.ReadObject () [0x000ed] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.PropertyListFormat+XmlFormat+Context.ReadDict (Xamarin.MacDev.PDictionary dict) [0x000c9] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.PropertyListFormat+ReadWriteContext.ReadObject () [0x000ed] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.PObject.FromByteArray (System.Byte[] array, System.Int32 startIndex, System.Int32 length, System.Boolean& isBinary) [0x00035] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.PDictionary.FromByteArray (System.Byte[] array, System.Int32 startIndex, System.Int32 length, System.Boolean& isBinary) [0x00001] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.PDictionary.FromBinaryXml (System.Byte[] array) [0x00041] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.MobileProvision.LoadFromFile (System.String fileName) [0x0000e] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.MobileProvisionIndex.GetMobileProvision (Xamarin.MacDev.MobileProvisionPlatform platform, System.String name, System.Collections.Generic.List`1[T] failures) [0x00026] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Xamarin.MacDev.Tasks.DetectSigningIdentityTaskBase.Execute () [0x0075a] in :0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:573
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(646,3): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x001f6] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:784
14 Warning(s)
1 Error(s)

If anyone has encountered this and has a resolution that would be brilliant. Alternatively if there's anything I haven't tried above that you know of that could help that would also be greatly appreciated. I've been working with Xamarin since the beta days and nothing has frustrated me as much as this!


  • I'm getting the same issue, its really annoying me. I have been using GitHub and a build worked a few days ago and now I am getting the same issue. I'm starting to think it is an issue on the server side of things

  • SBSDevSBSDev USMember ✭✭

    Yep. This is a legitimate and new problem. The provisioning profiles being generated from the Apple Developer account (either by automated tools like Fastlane or going through the UI) are now malformed. There is an embedded PLIST inside the .mobileprovision file and for some reason there are the possibility of duplicate internal keys like aps-environment. We encountered this as well as a duplicate key. If you generate and download a new provisioning profile and inspect it (look past the binary elements and find the plist, or even search for the aps-environment key) you will notice duplicates where previously there were none.

    Fastlane also broke a couple of days ago due to some change in Apple's handling of provisioning profiles (see as reference Fastlane issue 13916 on GitHub). I suspect this latest deployment of Apple's developer authority API generated various breaking regressions requiring mitigation.

    Bottom line is there are tools in the build chain that treat the entries in the embedded PLIST elements as just that - a dictionary with unique keys. We pulled the source for a plist editor we use (PListNet) and modified it temporarily to upsert instead of add so we got part of the way to the solution but then we ran into exactly what you show above.

    If anyone has cross-references to Apple's developer site, Fastlane, and/or other Xamarin issues, please link here. This is a clear problem that has basically caused a complete halt to any non-debug Xamarin iOS build.

  • SBSDevSBSDev USMember ✭✭

    As a follow-up, someone posted this similar issue on the Apple developer forum.

  • We're having the same issue with our build pipelines down. We've noticed that duplicate keys are added to the provisioning profile and are failing to be parsed by the build task.

    Added a Q to StackOverflow: Duplicate key in provisioning profile causes build failure error msb4018

    Looks like it will need a fix from Apple, and a workaround from the Xamarin team.

  • MattCrombieMattCrombie AUUniversity ✭✭

    Unbelievably frustrating. I've found disabling push notifications on the app in the Apple console works but obviously this is just a temporary solution to be able to continue development and testing. Looking forward to hearing about a proper fix to this soon.

  • RolfBjarneKvingeRolfBjarneKvinge USXamarin Team Xamurai

    This is a bug in Xamarin.iOS which was surfaced by a change on Apple's side.

    It's tracked here:

  • TheosTheos NLBeta ✭✭

    @RolfBjarneKvinge I noticed the change for this fix has been merged. Great work!
    How long do you think it will take to have an update for this available? (alpha channel?)

  • ben.laceyben.lacey USMember ✭✭
    edited December 2018

    I'm seeing something that I think is being caused by the same root cause...

    A new provisioning profile is correctly in ~/Library/MobileDevice/Provisioning Profiles (downloaded since the duplicate-key issue was present on the Apple side) but it is never added to the ~/Library/Xamarin/Provisioning Profiles.index file, which then leads to the error Could not find any available provisioning profiles for iOS. on building.

    Building with diagnostic verbosity shows other provisioning profiles are being considered but discarded correctly, it's just this new one that's 'invisible'.

    Does this sound like the same issue to you?

    [Edit] This does indeed seem to be the case - editing the mobileprovision file in the VS hex editor and cutting out the duplicated key/value fixes the build. Phew!

  • TheosTheos NLBeta ✭✭
    edited December 2018

    @ben.lacey I tried to edit the mobileprovision file on Mac with 2 different editors but getting an error while trying to load the profile "Profile is missing the required UUID property.". I only removed the duplicated <key>aps-environment</key> <string>development</string> part.

    What exactly did you do to make the profile work again?

  • ben.laceyben.lacey USMember ✭✭

    I opened the profile in Visual Studio (dragged into it and it opened in the hex editor view), placed the cursor on the starting bracket of the second aps-environment key and backspaced until it replaced the first. It seems to work, at least for now.

  • ConwayConway USMember ✭✭

    @Theos We had 4 duplicate entries in the profile and I had to remove all 4 duplicates with the hex editor before Visual Studio for Mac would load and use it. Maybe this is why it's not working for you?

    @ben.lacey Thanks for the work-around! I wasted hours on Friday trying to understand why the profile wasn't available in Visual Studio for Mac.

  • ben.laceyben.lacey USMember ✭✭

    You're welcome - I had a very similar experience on Friday!

    Although I've just tried to upload an IPA produced with a modified profile to App Store Connect and it was refused (The binary you uploaded was invalid.) so it might not be the best workaround, but it'll at least get some things building again :)

  • tyktyk USMember ✭✭

    Omg! I got crazy for three days. I cannot have build ipa with my new provisioning profiles. I navigated through all the web about provisioning issue. No solution-workaround left that I did not try.

  • ConwayConway USMember ✭✭

    I jumped the gun. I can now see and select the hex-edited provisioning profile in Visual Studio for Mac and the build uses it to successfully sign the app, but the app fails to install on a device with an invalid entitlements error (0xe8008016). If I try to open the profile in Xcode, I get the "Profile is missing the required UUID property" error that @Theos mentions.

  • TheosTheos NLBeta ✭✭

    @Conway I have the exact same situation. Editing the already installed profile let me select and build the app, only installing it on a real device won't work.
    I guess we've to wait for a change/fix from Apple or an update from Xamarin to handle the duplicated entries.

  • tyktyk USMember ✭✭

    I think apple verifies the integrity of provisioning profile while uploading the .ipa binary. It gives error since we change it by hex editor.

  • ConwayConway USMember ✭✭

    @RolfBjarneKvinge Is there any update on this issue? We are unable to build, deploy and debug for iOS...

  • tyktyk USMember ✭✭

    @RolfBjarneKvinge How can I replace new fixed "Xamarin.MacDev.dll" to old ones?

  • TheosTheos NLBeta ✭✭
    edited December 2018

    @RolfBjarneKvinge How can I replace new fixed "Xamarin.MacDev.dll" to old ones?

    I see that file is placed under:
    Really interested to see if you can make it work that way.

  • tyktyk USMember ✭✭

    @Theos I replaced that file in Mac and Windows wherever available. But I am getting the same dictionary duplicate issue error. What else I am missing, I don't know.

  • RiadRiad NLUniversity ✭✭
    edited December 2018

    Apparently Apple fixed the duplicate entry yesterday.
    But I am having another issue with the certificates. As many of you, I revoked, deleted, created certificates, exported to p12, 20 times I think. Now, I am not able anymore to export certificates to p12 format. In keychain, the certificates appear but the arrow with the private key is not there.
    Did I do something wrong with all these deletes and recreations or you are also facing this issue ?

    [Edit] Nevermind. It's working again.

  • TheosTheos NLBeta ✭✭

    I can confirm that Apple fixed the issue at their side.
    You only need to regenerate your provisioning profile again. After editing and generating it again I checked the content using a hex-editor and the duplicated entries were gone. Xamarin builds are working fine again.

  • MattCrombieMattCrombie AUUniversity ✭✭

    That's great news, was a little worried Apple wouldn't care because it didn't affect their product haha.

Sign In or Register to comment.