Note that there are some explanatory texts on larger screens.

plurals
  1. POInstancing with a dictionary
    primarykey
    data
    text
    <p>I am currently working on a project which creates a dictionary with an int index of the instance and a complex type as the value. Since this is a huge school project I do not want to post a ton of code as I have a logic problem rather than a "I need code". I'll try to be as clear as I can and if there is something I need to explain better please let me know.</p> <p>First off. I have a dictionary in my server:</p> <pre><code>private Dictionary&lt;int,List&lt;complexType&gt;&gt; dictName = new Dictionary&lt;int,List&lt;complexType&gt;&gt; </code></pre> <p>Every time a client starts up it registers with the dictionary (i create a blank complex type to instantiate it then i load the dictionary):</p> <pre><code>List&lt;complexType&gt; temp = null; dictName.Add(id,temp) </code></pre> <p>Then when the time comes that I want to add to the list for a particular instance I do this:</p> <pre><code>complexType myItem = new complexType(); dictName[id].Add(myItem); </code></pre> <p>When I run this code I get an error when a second client tries to run: </p> <blockquote> <p>"An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll. Additional information: Exception has been thrown by the target of an invocation.</p> </blockquote> <p>Now this happens when the second user hits: <code>dictName.Add(id,temp)</code> from the first part. </p> <p>If i change the instantiation of temp to <code>List&lt;complexType&gt; temp = new List&lt;complexType&gt;();</code></p> <p>then it passes that spot but I get the same error again when it updates the clients.</p> <p>I am currently using this way of passing data with int and string (dictionary) and they work fine but when I added in a List of a complex type in the dictionary I got the above error.</p> <p>If anyone has any suggestions I would greatly appreciate it. I'm hoping it has something to do with my initial load of a blank list. If there is anything else you need to know please Ask Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload