Asp.net mvc S#arp体系结构模型绑定器枚举错误
我收到SharpArchitecture模型绑定器的错误。“已修改集合;枚举操作可能无法执行。”(底部的堆栈跟踪) 要创建和编辑My设置模型的My MVC页面将抛出错误。当我们升级到S#arp架构1.0的发行版时,这种情况就开始出现了。我的类有一些列表作为属性。其中一个列表包含类,另一个列表作为属性。我不确定哪个列表抛出了错误。有人能提供关于如何解决这一问题或在我的模型中寻找可能导致这一问题的东西的方向吗 这是我的SettingsModel类:Asp.net mvc S#arp体系结构模型绑定器枚举错误,asp.net-mvc,s#arp-architecture,Asp.net Mvc,S#arp Architecture,我收到SharpArchitecture模型绑定器的错误。“已修改集合;枚举操作可能无法执行。”(底部的堆栈跟踪) 要创建和编辑My设置模型的My MVC页面将抛出错误。当我们升级到S#arp架构1.0的发行版时,这种情况就开始出现了。我的类有一些列表作为属性。其中一个列表包含类,另一个列表作为属性。我不确定哪个列表抛出了错误。有人能提供关于如何解决这一问题或在我的模型中寻找可能导致这一问题的东西的方向吗 这是我的SettingsModel类: public class SettingsMode
public class SettingsModel : Entity
{
public SettingsModel()
{
AttributeSettingsList = new List<AttributeSettingsModel>();
}
public virtual void AddAttributeSettings(AttributeSettingsModel attSettings)
{
AttributeSettingsList.Add(attSettings);
attSettings.Settings = this;
}
[NotNullNotEmpty(Message = "Description must be provided")]
public virtual string Description { get; set; }
[DomainSignature]
[Range(0, 100, Message = "ModelAPercentage must be between 0 and 100")]
public virtual int ModelAPercentage { get; set; }
[DomainSignature]
[Range(0, 100, Message = "ModelBPercentage must be between 0 and 100")]
public virtual int ModelBPercentage { get; set; }
public virtual IList<AttributeSettingsModel> AttributeSettingsList { get; set; }
public virtual IList<EntityMappingModel> EntityMappingList { get; set; }
public SettingsModel(string Description, int ModelAPercentage, int ModelBPercentage)
: this()
{
this.Description = Description;
this.ModelAPercentage = ModelAPercentage;
this.ModelBPercentage = ModelBPercentage;
}
}
以下是堆栈跟踪:
[InvalidOperationException:集合已修改;枚举操作可能无法执行。]
System.ThrowHelper.ThrowInvalidOperationException(异常资源)+51
System.Collections.Generic.Enumerator.MoveNextRare()+7661017
System.Collections.Generic.Enumerator.MoveNext()+61
SharpArch.Web.ModelBinder.SharpModelBinder.SetEntityCollectionProperty(ModelBindingContext bindingContext,PropertyDescriptor PropertyDescriptor,Object value)+358
SharpArch.Web.ModelBinder.SharpModelBinder.SetProperty(ControllerContext ControllerContext,ModelBindingContext bindingContext,PropertyDescriptor PropertyDescriptor,Object value)+61
System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext ControllerContext,ModelBindingContext bindingContext,PropertyDescriptor PropertyDescriptor)+265
SharpArch.Web.ModelBinder.SharpModelBinder.BindProperty(ControllerContext ControllerContext,ModelBindingContext bindingContext,PropertyDescriptor PropertyDescriptor)+225
System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext ControllerContext,ModelBindingContext bindingContext)+125
System.Web.Mvc.DefaultModelBinder.BindCompleteXelementalModel(ControllerContext ControllerContext,ModelBindingContext bindingContext,Object model)+293
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext ControllerContext,ModelBindingContext bindingContext)+772
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext ControllerContext,ModelBindingContext bindingContext)+345
SharpArch.Web.ModelBinder.SharpModelBinder.BindModel(ControllerContext ControllerContext,ModelBindingContext bindingContext)+39
System.Web.Mvc.DefaultModelBinder.UpdateCollection(ControllerContext ControllerContext,ModelBindingContext bindingContext,Type elementType)+408
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext ControllerContext,ModelBindingContext bindingContext)+756
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext ControllerContext,ModelBindingContext bindingContext)+345
SharpArch.Web.ModelBinder.SharpModelBinder.BindModel(ControllerContext ControllerContext,ModelBindingContext bindingContext)+39
System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext ControllerContext,ModelBindingContext bindingContext,PropertyDescriptor PropertyDescriptor)+231
SharpArch.Web.ModelBinder.SharpModelBinder.BindProperty(ControllerContext ControllerContext,ModelBindingContext bindingContext,PropertyDescriptor PropertyDescriptor)+225
System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext ControllerContext,ModelBindingContext bindingContext)+125
System.Web.Mvc.DefaultModelBinder.BindCompleteXelementalModel(ControllerContext ControllerContext,ModelBindingContext bindingContext,Object model)+293
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext ControllerContext,ModelBindingContext bindingContext)+772
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext ControllerContext,ModelBindingContext bindingContext)+345
SharpArch.Web.ModelBinder.SharpModelBinder.BindModel(ControllerContext ControllerContext,ModelBindingContext bindingContext)+39
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext ControllerContext,ParameterDescriptor ParameterDescriptor)+219
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor)+109
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext ControllerContext,String actionName)+399
System.Web.Mvc.Controller.ExecuteCore()+126
System.Web.Mvc.ControllerBase.Execute(RequestContext-RequestContext)+27
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext RequestContext)+7
ProcessRequest(HttpContextBase httpContext)+151
ProcessRequest(HttpContext HttpContext)+57
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext HttpContext)+7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+181
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+75sharp architecture SetEntityCollectionProperty方法中似乎存在错误。在最后四行:
foreach (object entity in (value as IEnumerable)) {
entityCollectionType.InvokeMember("Add",
BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, entityCollection,
new object[] { entity });
}
其目的似乎是从作为值传入的IEnumerable中的值填充模型集合类(entityCollection)。但是,这两个对象是相同的参照。已经有人住了。当调用“Add”方法时,entityCollection将被修改,该对象与正在迭代的对象相同。然后抛出异常
注释或删除该代码块,您的代码应该运行。注释该代码块是否会影响S#arp的其他功能
foreach (object entity in (value as IEnumerable)) {
entityCollectionType.InvokeMember("Add",
BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, entityCollection,
new object[] { entity });
}