2009-09-16 3 views
1

Я получаю сообщение об ошибке от связующего устройства модели SharpArchitecture. «Коллекция была изменена, операция перечисления не может выполняться». (След стека внизу).S # arp Ошибка архитектуры архитектуры связующего

Мои страницы MVC для создания и редактирования моих SettingsModel введите ошибку. Это началось, когда мы обновились до версии S # arp Architecture 1.0. В моем классе есть несколько списков как свойств. Один из списков содержит классы с другим другим списком как свойство. Я не уверен, какой список бросает ошибку. Может ли кто-нибудь дать указания относительно того, как устранить эту проблему или вещи, которые нужно искать в моих моделях, которые могут вызвать ее?

Это мой SettingsModel класс:

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; 
    } 

} 

Это метод SharpArchitecture бросает ошибку:

private void SetEntityCollectionProperty(ModelBindingContext bindingContext, 
     PropertyDescriptor propertyDescriptor, object value) { 

     if (value as IEnumerable != null && 
      IsSimpleGenericBindableEntityCollection(propertyDescriptor.PropertyType)) { 

      object entityCollection = propertyDescriptor.GetValue(bindingContext.Model); 
      Type entityCollectionType = entityCollection.GetType(); 

      foreach (object entity in (value as IEnumerable)) { 
       entityCollectionType.InvokeMember("Add", 
        BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, entityCollection, 
        new object[] { entity }); 
      } 
     } 
    } 

Вот трассировки стека:

[InvalidOperationException: коллекция была изменена; Операция перечисление не может выполнить.] System.ThrowHelper.ThrowInvalidOperationException (ExceptionResource ресурс): +51 System.Collections.Generic.Enumerator.MoveNextRare() +7661017 System.Collections.Generic.Enumerator.MoveNext(): +61 SharpArch. Web.ModelBinder.SharpModelBinder.SetEntityCollectionProperty (ModelBindingContext BindingContext, PropertyDescriptor PropertyDescriptor, значение объекта) +358 SharpArch.Web.ModelBinder.SharpModelBinder.SetProperty (ControllerContext controllerContext, ModelBindingContext BindingContext, PropertyDescriptor PropertyDescriptor, значение объекта): +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.BindComplexElementalModel (ControllerContext controllerContext, ModelBindingContext BindingContext, модель объекта) +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, Тип 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.BindComplexElementalModel (ControllerContext controllerContext, ModelBindingContext BindingContext, модель объекта) +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.ControllerActionInv oker.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 System.Web.Mvc.MvcHandler.ProcessRequest (HttpContextBase HttpContext) +151 System.Web.Mvc.MvcHandler.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 step, Boolean & completedSynchro nous) +75

ответ

0

Как представляется, в методе SetEntityCollectionProperty обнаружена ошибка. Его последние четыре строки:

 foreach (object entity in (value as IEnumerable)) { 
      entityCollectionType.InvokeMember("Add", 
       BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, entityCollection, 
       new object[] { entity }); 
     } 

Его цель, кажется, чтобы заполнить класс коллекции модели (EntityCollection) от значений в IEnumerable передается в качестве значения. Однако эти два объекта являются одной и той же ссылкой. Он уже заселен. Когда вызывается метод «Добавить», изменяется объект entityCollection, который является тем же самым объектом, который выполняется итерацией. Затем исключается исключение.

Прокомментируйте или удалите этот блок кода и ваш код должен работать.

0

Прокомментировать этот блок кода влияет на другие функции S # arp?

Смежные вопросы