Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity 5.0.2p2 KeyNotFoundException: The given key was not present in the dictionary.

Discussion in 'iOS and tvOS' started by CrystalDynamo, May 24, 2015.

  1. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Hi I was wondering if anyone is getting the following error, it has stumped me a bit.

    I have upgraded to Unity 5.0.2p2 and am running XCode Version 6.3.2 (6D2105) and when I try and build and run I get the follow error. It's only when building to run on iOS, in the Unity dev environment all works fine.

    To be honest I have had a google and still am , but have not put my finger on it. Does someone know if its a problem with the Unity Patch Release ?

    I just thought I would throw it out there in case someone knows the answer while I am still trying to work it out.

    The error is below : -


    KeyNotFoundException: The given key was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[System.String,UnityEditor.iOS.Xcode.PBX.PBXGroup].get_Item (System.String key) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
    UnityEditor.iOS.Xcode.PBXProject.RemoveGroupIfEmpty (UnityEditor.iOS.Xcode.PBX.PBXGroup gr)
    UnityEditor.iOS.Xcode.PBXProject.RemoveFilesByProjectPathRecursive (System.String projectPath)
    UnityEditor.iOS.PostProcessiPhonePlayer.BuildXCodeProject (UnityEditor.iOS.ProjectPaths paths, UnityEditor.iOS.IncludedFileList includedFiles, System.Collections.Generic.List`1 frameworks, System.String sdkVersion, System.String targetOS, System.String productName, Boolean useIl2Cpp, Boolean installInBuildFolder, Boolean useSymlinks, Boolean isGameCenterUsed)
    UnityEditor.iOS.PostProcessiPhonePlayer.PostProcess (UnityEditor.iOS.iOSBuildPostprocessor pp, BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String stagingAreaDataManaged, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry)
    UnityEditor.iOS.iOSBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
    UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()




    Mike
     
    bokim likes this.
  2. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Hmm further tests on my macbook pro indicate it works with x-Code Version 6.3.1 (6D1002).

    I'll roll back my code on the main dev mac and see if that works with the latest xCode version.
    I haven't made many changes at all. If it works I'll gently cut and paste them back into the code
    and see if that stabilises everything.

    Fingers crossed.
     
    Laik likes this.
  3. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    I removed the entire project folder and restored a backup one and it all works. Somehow something in there screwed up the project. Backups are good. The auto launch of XCode Version 6.3.2 (6D2105) doesn't work but manually loading the generated project and deploying it from XCode works. Hopefully I will find the offending new code as it goes back in. I'd love to know what it was to post it here for reference.
     
  4. nindim

    nindim

    Joined:
    Jan 22, 2013
    Posts:
    130
    I've got the same problem with Unity 5.0.2p1 and Xcode 6.3.1.

    Fully replacing the build rather than appending seems to sort it... :/
     
  5. Martin-S

    Martin-S

    Joined:
    Nov 19, 2012
    Posts:
    11
    I reported a similar bug in 4.6.5p2. It's case number 698720.
     
  6. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Thanks.

    I found after the build attempt if you go and manually open the Xcode project compile and deploy it from Xcode it all seems to run on the deployed target device..

    So when I select build and run in Unity regardless of a code replace it still generates the KeyNotFoundException and then I get the can't launch x-code error and it stops the build. Then I manually open x-code and open up the new generated Xcode project and tell Xcode to build and run and it runs.

    Its all a bit dubious I think. Does that KeyNotFoundException mean I have a problem that I have to fix or is it a unity bug or can it be ignored I have no idea. I don't want to continue and waste my time if I did something wrong. :(
     
  7. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    If anyone knows what the KeyNotFoundException error is please let me know. In the mean time hopefully I'll find something googling.

    I hope Unity iOS Development is not becoming unstable. Fingers crossed.
     
  8. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    it is an error in our "append to xcode project" script. Nothing bad is happening. Just always select replace. Now, before you start swearing at me - i know it is huge PITA and it is being worked on
     
  9. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Thats ok , as long as I know. I just wanted to make sure I could continue forward coding and it wasn't something in my code doing it. So I'll just continue on until it disappears then and not bother trying to analyse it further.

    The only reason I stopped on it was I have my previous days backup and the error doesn't occur and I did a bunch of script modifications and after that it started appearing. I went through all the code and it was nothing dramatic and couldn't find anything and was wondering if it only occurs in certain circumstances. So my code should be good to go I guess. When I run x-Code manually it seems fine.

    I might put the working at non working backups to the side in case I need to reference it in the future and it is a certain syntax just to be safe.

    Thanks for your response.
     
  10. cesarpo

    cesarpo

    Joined:
    Jun 8, 2013
    Posts:
    97
    Just had the same problem, on the same unity version.

    Let us know when this is fixed @Alexey
     
  11. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    This issue has been fixed. The fix will appear in 4.6.6p1 and 5.0.3.
     
  12. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Cool thanks povilas.
     
  13. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    273
    Is there any possible way that you can pre-release your fixed ""append to xcode project" script"? We really need to fix this today and we can't use the "Replace" option. Is there a way we can manually replace that script of yours with your fixed version in the Unity engine?
     
  14. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    At this stage I do the following : -

    I opened finder and found the folder that unity makes the xcode project in. Then I created an alias to that folder and stuck it on my mac toolbar.

    Now when I want to build and run in Unity I just run Build from the Build Options screen. That runs with no errors. Once that is complete I click the shortcut to the folder on my toolbar and double click the project to open it in xCode and once it is open I just select build and run to run it on my device.

    No errors at all as the workaround.

    NOTE: I always select replace when I do this. (added this note after the original post)
     
    Last edited: Jun 7, 2015
  15. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    273
    Thanks for sharing Psyconic! Although not sure how this helps when building from Unity with the "Append" option. That's what causes the issue for me. If I build with "Replace" it works without errors and like you said I can go and open the XCode project manually.
    But the errors appears as soon as I try to build with "Append". I guess one option would be to automate the XCode project setup every time and use only "Replace". :(
     
  16. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Hmm I'll have to check that with mine.

    Ahh yes I always check replace that's why I am not getting it. Probably out of habit now.

    I will modify my original post.
     
  17. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    273
    I've managed to make my own manual "append" process. In case someone else is in need of an urgent temporary solution for building with "Append" using Unity 4.6.5p4 you can try this:
    - keep a backup of the last XCode project that you built with "Append"
    - make the Unity build with "Replace" to avoid the KeyNotFoundException error
    - then from the last backed up XCode project you can copy and overwrite all the files except the ones from the "Library", "Classes" and "Data" folders. Bare in mind that you will overwrite the "Unity-iPhone.xcodeproj" file too (don't worry about it).
    - then you have to open the XCode project and go and manually add any new files Unity's IL2CPP might have generated by right-clicking the "Libraries" folder group and selecting the option "Add files to..." where XCode will highlight files that having been added to the XCode project.
    - repeat the above step for the folder "Classes/Native". This is where IL2CPP will generate new native files. Again "Add files to..." and you can try to select all using CMD+A key, it will only select the new files (if there are any).

    After the above steps you should have all the changes "appended" to your XCode project and you should be able to build and run from the XCode project. Desperate times calls for desperate measures. :)

    It's a tedious manual process but if Unity doesn't manage to fix this issue you can script it and automate it until they do. It worked ok for me.
     
    Last edited: Jun 8, 2015
  18. cesarpo

    cesarpo

    Joined:
    Jun 8, 2013
    Posts:
    97
    Man, that sucks, I wonder if this is fixed in 5.1 RC2 ?

    I had to remove the xcode project from the repo because it was killing git with 7k modifications in each build/replace.
     
  19. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    273
    The issue still happens on my builds when I try to "Append" build with Unity 4.6.6f2. Only now the error is different and it just says:
    "Error building Player: ArgumentException: An element with the same key already exists in the dictionary."

    Could you guys please output more details about this "key" so we may manually remove it from the XCode project and let the Unity build add it back maybe?
    And for future errors it might help to give more details in the editor log. :(
     
  20. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Yeah, I just got a key error doing an append build in 4.6.6 too.
     
  21. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    273
    "Fun" fact...I tried a new simple project with just 1 script and it still happens. Sooo it's not related to my other bigger project either.
    But in this other test project with just one dummy script it throws the previous known error:
    "Error building Player: KeyNotFoundException: The given key was not present in the dictionary."
     
  22. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    273
    Just tried using Unity 4.6.6p1. Still the same problem. :(
    Is this bug being tested in a hurry or is it just me? :-/
    P.S. Using XCode 6.2. Could this be a problem? Will further investigate and try to isolate the problem in a separate small project and submit it as a new bug report.
     
  23. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    This is still happening for me with Unity 5.0.2p1 and xCode 6.3.2
     
  24. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    @floky I think your issue is a bit different. Could you please submit your project attached to a bug report and post the bug number here?
     
  25. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    I am going to play with this code from QI and see if I can make a work around.


    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. public class BuildForiOS : MonoBehaviour {
    4.     [MenuItem("File/Build For iOS (Development)")]
    5.     static void BuildForiOSDevelopment(){
    6.         //Get all scenes from build setting UI.
    7.         EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
    8.         string[] scenesPath = new string[scenes.Length];
    9.         for (int i = 0; i < scenesPath.Length; i++) scenesPath[i] = scenes[i].path;
    10.         //Select where to save files
    11.         string previousPath = EditorPrefs.GetString ("BuildForiOS.PreviousPath", Application.persistentDataPath);
    12.         string destination = EditorUtility.SaveFilePanel ("Choose a destination", previousPath, EditorPrefs.GetString("BuildForiOS.Name",""), "");
    13.         //Check if user canceled the action.
    14.         if (!string.IsNullOrEmpty (destination)) {
    15.             //Saving settings for the next build.
    16.             string name = destination.Substring(destination.LastIndexOf("/") + 1);
    17.             EditorPrefs.SetString ("BuildForiOS.PreviousPath", destination.Substring(0,destination.LastIndexOf("/")));
    18.             EditorPrefs.SetString("BuildForiOS.Name", name);
    19.             //Build the player
    20.             BuildPipeline.BuildPlayer (scenesPath, destination, BuildTarget.iOS, BuildOptions.Development | BuildOptions.ShowBuiltPlayer | BuildOptions.Il2CPP);
    21.         }
    22.     }
    23. }
     
  26. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    273
    @povilas I can confirm that using 4.6.6p1 in a separate simple Unity project without any other libraries or postprocess steps, build with "Append" works correctly with XCode 6.2.

    Will try to isolate the problem in our other bigger project and send you a bug report. I think it's a combination of factors due to the fact that we're using some Unity libs that in the postprocess step they change the XCode project (adding/updating frameworks, etc.) For example the Facebook Unity SDK is a first suspect of this problem. Not sure yet. Stay tuned! :)
     
  27. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    I have 2 versions of my Unity 5 source that are on the same unity and Xcode version. 2 days apart.

    I only modified a few c# functions and one generates the error and the other doesn't. If I narrow it down to use of a specific syntax causing it I'll post it here.
     
  28. AwDogsGo2Heaven

    AwDogsGo2Heaven

    Joined:
    Jan 17, 2014
    Posts:
    102
    Updated Unity today and this started happening, no idea what to do to fix it.

    Tried deleting temp files, build folder ect..nothing works.
     
  29. cesarpo

    cesarpo

    Joined:
    Jun 8, 2013
    Posts:
    97
    It's fixed in 5.1
     
  30. AwDogsGo2Heaven

    AwDogsGo2Heaven

    Joined:
    Jan 17, 2014
    Posts:
    102
    Thats what I just updated to. Everything was working until update.

    KeyNotFoundException: The given key was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[System.String,UnityEditor.iOS.Xcode.PBX.PBXGroup].get_Item (System.String key) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
    UnityEditor.iOS.Xcode.PBXProject.GroupsGetByChild (System.String childGuid)
    UnityEditor.iOS.Xcode.PBXProject.RemoveGroupIfEmpty (UnityEditor.iOS.Xcode.PBX.PBXGroup gr)
    UnityEditor.iOS.Xcode.PBXProject.RemoveFilesByProjectPathRecursive (System.String projectPath)
    UnityEditor.iOS.PostProcessiPhonePlayer.BuildXCodeProject (UnityEditor.iOS.ProjectPaths paths, UnityEditor.iOS.IncludedFileList includedFiles, System.Collections.Generic.List`1 frameworks, System.String sdkVersion, System.String targetOS, System.String productName, Boolean useIl2Cpp, Boolean installInBuildFolder, Boolean useSymlinks, Boolean isGameCenterUsed)
    UnityEditor.iOS.PostProcessiPhonePlayer.PostProcess (UnityEditor.iOS.iOSBuildPostprocessor pp, BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String stagingAreaDataManaged, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry)
    UnityEditor.iOS.iOSBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
    UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

    This is the full print out.. pretty much sucks, makes deploying really difficult and time consuming
     
  31. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    I am a bit confused 5.1.0p1 came out 12th June then 5.0.3p2 is out on 18th June.

    Are there 3 streams now ?

    I am off to test 5.1.0p1 now.
     
  32. AwDogsGo2Heaven

    AwDogsGo2Heaven

    Joined:
    Jan 17, 2014
    Posts:
    102
    I'm confused too Psyconic, I just opened Unity and it said it had an update, I clicked it and it installed 5.1.1 <.>. Maybe I should try installing 5.0.3p2 instead
     
  33. AwDogsGo2Heaven

    AwDogsGo2Heaven

    Joined:
    Jan 17, 2014
    Posts:
    102
    my xcode is 6.3.2 , I also thought about going back to 6.3.1 since I updated the same day I installed this new unity..

    EDIT:

    6.3.1 doesn't fix the issue, going to try reverting back to 5.0.3.
     
    Last edited: Jun 20, 2015
  34. AwDogsGo2Heaven

    AwDogsGo2Heaven

    Joined:
    Jan 17, 2014
    Posts:
    102
    Switching back to 5.0.3 worked. Soo guess no 5.1.1 until they fix it with XCode. Bummer! Wish it would tell you exactly what 'Key' it was looking for in the dictionary...could be useful in figuring out the issue.
     
  35. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    I am still confused. The patch release page seems inconsistent. I just don't want to take my project files down one path and have them get corrupted because that path was a dead end. Is 5.1.0 the correct path or do we need to back out to 5.0.3 ?
     
  36. hadikazemi

    hadikazemi

    Joined:
    May 30, 2013
    Posts:
    5
    I updated Unity to 5.1.1f1 and my project was working till a hour ago. But since I Built it ... I have had the same problem ...
     
  37. Nickyj

    Nickyj

    Joined:
    May 26, 2015
    Posts:
    1
  38. AndreaP

    AndreaP

    Joined:
    Dec 28, 2012
    Posts:
    50
    It's happening to me on Unity 5.1.1f
     
  39. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Yep the moment you try an append build on 5.1.0p1 does it.
     
  40. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Ok I found the status of the patches streams.

    from here

    http://forum.unity3d.com/threads/unity-patch-releases.246198/page-2
     
  41. AwDogsGo2Heaven

    AwDogsGo2Heaven

    Joined:
    Jan 17, 2014
    Posts:
    102
    They need to get on this error then! Hope its fixed in 5.1.2, or else they are not going to be seeing many iOS people moving over...
     
  42. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,058
    Wow, so there have been 3 public releases of Unity in June and numerous releases since this error was posted.... why is this not fixed yet even in v5.1.1?!
     
  43. SimonAlkemade

    SimonAlkemade

    Joined:
    Feb 4, 2009
    Posts:
    432
    Same error here...
     
  44. fschneider

    fschneider

    Joined:
    May 26, 2014
    Posts:
    42
    I just updated to 5.1.1 and this just happened. I _was_ using "Replace"
     
  45. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Did you just select build or build and run ?

    I just select build and at the end it opens finder so you can double click on the xcode project. Then you build and run from xcode.
     
  46. fschneider

    fschneider

    Joined:
    May 26, 2014
    Posts:
    42
    Build and run. It works as you described. Would however be nice if it worked without the workaround.
    Btw, just saw that 5.1.1p1 was released two days ago. The release notes contained something about the append scenario.
     
  47. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    How did you get 5.1.1. in the first place its not on the patch screen ?

    I am running 5.1.0p1 thats what I thought people meant when they posted 5.1.1 .

    Bloody hell I just answered that LOL its on the main download screen.
     
  48. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    I am upgrading now to test. Thanks for letting me know about that.
     
  49. fschneider

    fschneider

    Joined:
    May 26, 2014
    Posts:
    42
    So I just upgraded to 5.1.1p1, and after I issued a "Build", selecting "Append", I received the following error:

    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.iOS.Xcode.PBXProject.GetGroupChildrenFiles (System.String projectPath)
    UnityEditor.iOS.PostProcessiPhonePlayer.BuildXCodeProject (UnityEditor.iOS.ProjectPaths paths, UnityEditor.iOS.IncludedFileList includedFiles, System.Collections.Generic.List`1 frameworks, System.String sdkVersion, System.String targetOS, System.String productName, Boolean useIl2Cpp, Boolean installInBuildFolder, Boolean useSymlinks, Boolean isGameCenterUsed)
    UnityEditor.iOS.PostProcessiPhonePlayer.PostProcess (UnityEditor.iOS.iOSBuildPostprocessor pp, BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String stagingAreaDataManaged, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry)
    UnityEditor.iOS.iOSBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
    UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316)
    UnityEditor.HostView:OnGUI()
     
  50. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    The Key not found exception appears to have gone under 5.1.1p1 it just won't launch xCode now so you will have to do that manually I guess. That's no biggy I guess and will always be a drama with two pieces of software trying to keep the xcode run build and deploy scripting in sync with unity and xcode releases. I can live with that. They should just open finder like they do on the build only option.