How is this Dictionary exception possible?

后端 未结 6 1188
遥遥无期
遥遥无期 2021-01-12 02:28

Given the following stack trace:

MESSAGE: Value cannot be null.Parameter name: key  
SOURCE: mscorlib  
TARGETSITE:          


        
6条回答
  •  长发绾君心
    2021-01-12 02:40

    Not sure about the null but why aren't you using:

    internal static KeyValuePair[] Convert(IDictionary from)
    {
        return from.ToArray();
    }
    

    Edit: As far as the null values are concerned. Do you have multiple threads accessing this IDictionary? Corruption is possible if you're not being thread safe. See this post for an example of corruption in the

    Queue
    

    class. How can I modify a queue collection in a loop?

提交回复
热议问题