Dictionary使用add方法时出现了索引超出界限,不知啥原因

linxi1151 2012-01-16 10:42:12
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Microsoft.Practices.ObjectBuilder.WeakRefDictionary`2.Add(TKey key, TValue value)
at Microsoft.Practices.ObjectBuilder.Locator.Add(Object key, Object value)
at EMenuData2.Entities.EntityLocator.Add(String key, Object value)
at EMenuData2.Entities.EntityManager.StartTracking(String key, IEntity entity, Boolean isTrackingEnabled)
at EMenuData2.Entities.EntityManager.LocateOrCreate[Entity](String key, String typeString, Type entityFactoryType, Boolean isLocatorEnabled)
at EMenuData2.Data.Bases.PrintDetailProviderBaseCore.Fill(IDataReader reader, TList`1 rows, Int32 start, Int32 pageLength)
at EMenuData2.Data.SqlClient.SqlPrintDetailProviderBase.Find(TransactionManager transactionManager, IFilterParameterCollection parameters, String orderBy, Int32 start, Int32 pageLength, Int32& count)
at EMenuData2.Data.Bases.EntityProviderBaseCore`2.Find(TransactionManager transactionManager, IFilterParameterCollection parameters, String orderBy)
at EMenuData2.Data.Bases.EntityProviderBaseCore`2.Find(TransactionManager transactionManager, IFilterParameterCollection parameters)
at EMenuData2.Data.Bases.EntityProviderBaseCore`2.Find(IFilterParameterCollection parameters)
at PrintService.PrintThread.PrintRecordWithState.PrintThread()
at PrintService.PrintThread.PrintRecordWithState.PrintService.PrintThread.Operation.Start()PrintRecordStart
记录位置: 在PrintService.PrintThread.Operation.Start 位置:行号:0
...全文
715 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ny-6000 2012-01-16
  • 打赏
  • 举报
回复
+![Quote=引用 5 楼 findcaiyzh 的回复:]
或者加入了一个key,但是它已经存在了。
用ContainsKey检查一下先。
[/Quote]
ouyang4683 2012-01-16
  • 打赏
  • 举报
回复
多线程访问的原因吧
赤脚的蜈蚣 2012-01-16
  • 打赏
  • 举报
回复
在报错的时候,看看Dictionary已经存了几条,看看它的Count.
回头是岸 2012-01-16
  • 打赏
  • 举报
回复
不要在操作集合的时候去修改集合里的东西
最常见的就是循环自身的时候去更新集合里的东东
宝_爸 2012-01-16
  • 打赏
  • 举报
回复
或者加入了一个key,但是它已经存在了。
用ContainsKey检查一下先。
宝_爸 2012-01-16
  • 打赏
  • 举报
回复
多线程访问了吧。
Dictionary不是线程安全的,试一试lock。
赤脚的蜈蚣 2012-01-16
  • 打赏
  • 举报
回复
弄错了,Dictionary是无法设置容量值的,不好意思。
linxi1151 2012-01-16
  • 打赏
  • 举报
回复
有什么限制吗,能说的具体点吗?
赤脚的蜈蚣 2012-01-16
  • 打赏
  • 举报
回复
检查一下是否设定了容量值,或数据量太大了。
linxi1151 2012-01-16
  • 打赏
  • 举报
回复
是单线程内的局部变量,没有多线程访问!

111,095

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧