Using Generic Dictionaries Can Crash Debuging -- Understanding Why. RRS feed

  • Question

  • I posted this on GotSpeech.NET as well....


    This is not so much a problem as it is a question of not understanding what is happening behind the scenes.

    I instantiate a generic Dictionary and create a property to access it in the Main Workflow class like this...

    private Dictionary<string, object> session = new Dictionary<string, object>();

    public Dictionary<String, Object> Session
    get { return session; }
    set { session = value; }

    Then I assign a value to the dictionary in the Workflow constructor like this...

    Session.Add("InstitutionID", InstitutionID);

    and then when debuging, I get this error when I put a break point on a workflow activity....


    An error occurred while loading the workflow. Please correct the following error and try reloading the document to view the workflow.


    plus I get a link to the XOML that reads


    CreateInstance failed for type 'System.Collections.Generic.Dictionary '2'. Cannot create an instance of the System.Collections.Generic.Dictionary'2'[TKey,TValue] because Type.ContainsGenericParameters is true...


    If I run the code in NON debug mode or remove the break point everything runs fine.

    Also if I move the Session.Add code outside the constructor to for example a code activity, then debuger works as well.

    My questions is why?  Could someone shed some light on what is happening behind the scene?


    Thursday, October 4, 2007 4:27 PM