Adding to a generic dictionary causes IndexOutOfRangeException

前端 未结 3 1277
孤城傲影
孤城傲影 2021-02-03 21:05

I\'m using a dictionary inside of some Task.

Logically I have set it up so that my Keys will never clash, though sometimes when I am adding to the dictionary I get this

3条回答
  •  醉话见心
    2021-02-03 21:39

    So you might think Whatever! it will just break the one time - but nope:

    Important: Once the dictionary is broken it is broken!

    There goes three hours of sales (until IIS recycled on a schedule) because of a dictionary added for debugging purposes that wasn't ever even being read from.

    Note: This was running for 3.5 years before I hit this condition.

     private Dictionary _debugLookup;
    
     _debugLookup[key] = virtualPath;
    

    This wasn't even a static dictionary - it was an MVC IViewLocationCache that was an instance method.

提交回复
热议问题