Search Unity

The given key was not present in the dictionary.

Discussion in 'Flash' started by jstriedinger, Aug 16, 2012.

  1. jstriedinger

    jstriedinger

    Joined:
    Apr 19, 2011
    Posts:
    58
    Ok, this is KILLING me.
    A while I go Unity showed up this error when building to Flash:
    The given key was not present in the dictionary.
    Stacktrace: at System.Collections.Generic.Dictionary`2[System.String,System.Int32].get_Item (System.String key) [0x00000] in <filename unknown>:0

    So yeah, it does not says WHERE is the mistake. I know about the error but, damn there are just oo many scripts in this project. Can somebody help me???
     
    Last edited: Aug 16, 2012
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Given there is a stack trace and a key not found error, it can't be a build time error as code is not executed during build.
    Best to do is building a dev build and see what you get to see on the flash side or alternatively test the player within Unity cause that will throw an error then there on which you can click to even get the game object marked
     
  3. jstriedinger

    jstriedinger

    Joined:
    Apr 19, 2011
    Posts:
    58
    Thanks!
    I'll try that
     
  4. DDowell

    DDowell

    Joined:
    Feb 8, 2012
    Posts:
    52
    We just came across this error. It seems like Unity+Mono+Flash exporter doesn't handle switch-case statements very well (especially when you have many cases or non-sequential cases). Try changing all your switch-cases to if-else. That solved it for us.
     
  5. Frooxius

    Frooxius

    Joined:
    Aug 15, 2012
    Posts:
    57
    Hello,
    I have exactly the same problem and I have no luck solving it at all :-( I tried changing all the switches to if-else-if ladders, but that didn't solve the problem and I don't know what else to try, besides randomly changing pieces of the code since the exception isn't helpful to pinpoint the location of the problem at all.

    I tried reporting bug to Unity too, but that was more than two weeks ago (or three maybe) and still got absolutely no answer and it's getting more urgent, so if anyone knows what else might be causing this, I would appreciate it.

    My project uses solely C# by the way.

    Code (csharp):
    1.  
    2. The given key was not present in the dictionary.
    3. Stacktrace:   at System.Collections.Generic.Dictionary`2[System.String,System.Int32].get_Item (System.String key) [0x00000] in <filename unknown>:0
    4.   at SwfPostprocessor.UnityCompiler.cfg.ControlFlowGraph.ProcessBlock (SwfPostprocessor.UnityCompiler.cfg.BasicBlock block, Int32 depth) [0x00000] in <filename unknown>:0
    5.   at SwfPostprocessor.UnityCompiler.cfg.ControlFlowGraph.ProcessBlocks () [0x00000] in <filename unknown>:0
    6.   at SwfPostprocessor.UnityCompiler.cfg.ControlFlowGraph.CreateBasicBlocks () [0x00000] in <filename unknown>:0
    7.   at SwfPostprocessor.UnityCompiler.cfg.ControlFlowGraph..ctor (SwfPostprocessor.UnityCompiler.Disassembler.DisassembledMethodBody dmb) [0x00000] in <filename unknown>:0
    8.   at SwfPostprocessor.UnityCompiler.Assembler.DmbAssembler.RecompileBody (SwfPostprocessor.UnityCompiler.Disassembler.DisassembledMethodBody dmb, Int32 bodyCount) [0x00000] in <filename unknown>:0
    9.   at SwfPostprocessor.UnityCompiler.CompilerUnity.ProcessMethodBody (SwfLibrary.Abc.Abc46 abc, SwfLibrary.Abc.MethodBodyInfo body) [0x00000] in <filename unknown>:0
    10.   at SwfPostprocessor.UnityCompiler.CompilerUnity.Compile () [0x00000] in <filename unknown>:0
    11.   at SwfPostprocessor.Configuration.SwfPostProcessorRunConfigurationUpp.Run () [0x00000] in <filename unknown>:0
    12.   at SwfPostprocessor.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
    13.  
    14.  
    15. Error building Player: Exception: C:/Program Files (x86)/Unity4/Editor/Data/PlaybackEngines/FlashSupport\BuildTools\SwfPostProcessor.exe Failed:
    16. Starting : UPP
    17.  
    18. ERROR: The given key was not present in the dictionary.
    19. Stacktrace:   at System.Collections.Generic.Dictionary`2[System.String,System.Int32].get_Item (System.String key) [0x00000] in <filename unknown>:0
    20.   at SwfPostprocessor.UnityCompiler.cfg.ControlFlowGraph.ProcessBlock (SwfPostprocessor.UnityCompiler.cfg.BasicBlock block, Int32 depth) [0x00000] in <filename unknown>:0
    21.   at SwfPostprocessor.UnityCompiler.cfg.ControlFlowGraph.ProcessBlocks () [0x00000] in <filename unknown>:0
    22.   at SwfPostprocessor.UnityCompiler.cfg.ControlFlowGraph.CreateBasicBlocks () [0x00000] in <filename unknown>:0
    23.   at SwfPostprocessor.UnityCompiler.cfg.ControlFlowGraph..ctor (SwfPostprocessor.UnityCompiler.Disassembler.DisassembledMethodBody dmb) [0x00000] in <filename unknown>:0
    24.   at SwfPostprocessor.UnityCompiler.Assembler.DmbAssembler.RecompileBody (SwfPostprocessor.UnityCompiler.Disassembler.DisassembledMethodBody dmb, Int32 bodyCount) [0x00000] in <filename unknown>:0
    25.   at SwfPostprocessor.UnityCompiler.CompilerUnity.ProcessMethodBody (SwfLibrary.Abc.Abc46 abc, SwfLibrary.Abc.MethodBodyInfo body) [0x00000] in <filename unknown>:0
    26.   at SwfPostprocessor.UnityCompiler.CompilerUnity.Compile () [0x00000] in <filename unknown>:0
    27.   at SwfPostprocessor.Configuration.SwfPostProcessorRunConfigurationUpp.Run () [0x00000] in <filename unknown>:0
    28.   at SwfPostprocessor.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
     
  6. Ghisallo

    Ghisallo

    Joined:
    Sep 27, 2012
    Posts:
    10
    Oh my, I just got this same error when building my Flash project. Has anyone found a solution?
     
  7. Ghisallo

    Ghisallo

    Joined:
    Sep 27, 2012
    Posts:
    10
    After much trial and error I finally found the source of the error in my code. Quite simply it was a break statement within a for loop. More specifically, the break statement in the snippet below. Once commented out, it compiled without error.

    Interestingly, I have break statements elsewhere in the project without any ill effect. Hope this helps someone else.

    Code (csharp):
    1. for (var u in users)
    2.     {
    3.         if ( u.StartsWith(loggedInUser) )
    4.         {
    5.             var uEntry : String[] = u.Split(","[0]);
    6.             if ( uEntry[0] == loggedInUser ) // must match exactly
    7.             {
    8.                 folder = uEntry[2];
    9.                 //break;
    10.             }  
    11.  
    12.         }  
    13.     }
     
  8. Nodrap

    Nodrap

    Joined:
    Nov 4, 2011
    Posts:
    83
    Hi there,

    Latest victim to this bug reporting in! Was trying my first build to Android for my latest project in 4.2 (non pro). Failed as above, tried to remove any unneeded breaks in for loops, tried completely commenting out my very large switch statement (which has many non sequential entries) and still it kicks out this "key" error.

    The really weird thing though is if I just try to build the APK instead of build to device then it all works and the resultant APK works fine. Weird. Just thought I'd pass on the feedback in the hope that Unity are listening.
     
  9. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    The code generated by the Flex compiler sometimes emits jumps to labels that don't exist (because they are actually outside of the cfg). We tried to mitigate this as good as we can (by changing what code we generate), however, there might (and apparently are) still cases. Please report bugs with reproduction projects for us to fix this.