entity-framework-6 - AutoMapper.AutoMapperMappingException:System.InvalidOperationException:集合已修改;枚举操作可能无法执行
问题描述
描述:我有一个使用 Automapper 4.1.1.0 版本和 EF 6 进行映射的 Web 应用程序。
当获取更多记录和/或更多并发用户在此应用程序上操作时,此应用程序会间歇性地抛出错误。
错误详情:
System.Data.Entity.DynamicProxies.Product_8AFB94389ADEA7181732D39AAE7B3AAB16F6979897F600C1B5E2A8F50A0AFDFDError Token:637170760073663598
AutoMapper.AutoMapperMappingException:
Mapping types:
Product -> ProductBO
Org.app.Entity.DataModel.Inventory.Product -> Org.app.BusinessObjects.Models.ProductBO
Destination path:
List`1[35]
Source value:
System.Data.Entity.DynamicProxies.Product_8AFB94389ADEA7181732D39AAE7B3AAB16F6979897F600C1B5E2A8F50A0AFDFD ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at AutoMapper.TypeMap.<get_AfterMap>b__40_0(Object src, Object dest)
at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.Map(ResolutionContext context, IMappingEngineRunner mapper)
at AutoMapper.Mappers.TypeMapMapper.Map(ResolutionContext context, IMappingEngineRunner mapper)
at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
--- End of inner exception stack trace ---
搜索 API 调用
products.Result = Mapper.Map<List<ProductBO>>(ProductList.ToList())
它有一个自定义的自动映射器配置类
public static class AutoMapperConfiguration
{
public static void Configure()
{
Mapper.CreateMap<Product, ProductBO>()
..
这是从 Startup.cs 调用的 AutoMapperConfiguration.Configure();
这个版本的 Automapper 有人遇到过这个问题吗?如果您能提供解决此问题的任何想法,将不胜感激。
谢谢
解决方案
推荐阅读
- python - 我将如何找到数字 Python 的不同数字
- angular - 如何让我的前端和后端在 Angular 中相互通信?
- wordpress - 带有木材的 ACF 未显示在首页上
- ruby - 有人能帮我理解 Ruby 手册中 str.counts 的例子吗?
- reactjs - 组件重构为自己的文件时路由不呈现视图
- c# - Net Core:使用命令行更改“包管理器控制台”Nuget 中的“默认项目”
- python - 如何使用按钮销毁程序中当前打开的每个屏幕
- javascript - 使用 Javascript 更改基于 getMonth() 的链接类
- configuration - 自动化脚本:从相关表中获取值
- gradle - Gradle 构建时“getMessageBus 不得返回 null”