문제

SharpArchitecture 모델 바인더에서 오류가 발생했습니다."컬렉션이 수정되었습니다.열거 작업이 실행되지 않을 수 있습니다." (하단의 스택 추적)

내 MVC 페이지를 생성하고 편집하려면 설정모델 오류를 던집니다.이는 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 });
            }
        }
    }

스택 추적은 다음과 같습니다.

[InvalidOperation예외:컬렉션이 수정되었습니다.열거 작업이 실행되지 않을 수 있습니다.] System.throwHelper.throwInValidOperationException (ExceptionResource Resource) +51 System.Collections.generic.enumerator.movenextrare () +7661017 System.Collections.generic.enumerator.movenext () +61 Sharparch.wewb.wewb.wewb.wewb.wewb.wewb.wewb.wewb.wew SharpModelBinder.setEntityCollectionProperty (ModelBindingContext BindingContext, PropertyDescriptor PropertyDescriptor, 객체 값) +358 SharParch.Web.ModelBinder.SharpModelBinder.SetProperty (ControlLerContext ControlLerconText, ModelBindText valueT, PropertyDScriptor) MVC.DefaultModelBinder.BindProperty (ControlLerContext ControlLerConText, ModelBindingContext BindingContext, PropertyDescriptor PropertyDescriptor) +265 SharParch.web.ModelBinder.SharpModelBinder.BindProperty (ControlLerConText ControlLerContext, ModelBindingContext BindingContext, PropertyDescriptor) OperTies (ControlLerConText ControlLerContext, ModelBindingContext BindingContext) +125 시스템 .web.mvc.defaultmodelbinder.bindcomplexElementalModel (ControlLerConText ControlLerContext, ModelBindingContext BindingContext, Object Model) +293 System.Web.mvc.defaultModelBinder.BindClexModel (ControlLerContext ControlleConText) +772). .DefaultModelBinder.BindModel (ControlLerConText ControlLerContext , ModelBindingContext BindingContext) +345 sharparch.web.modelbinder.sharpmodelbinder.bindmodel (ControllerConText ControlLerContext, ModelBindingContext BindingContext) +39 System.Web.mvc.defaultModelBinder.upDAteCollection (ControlLerContext, eUpDAteCollection) +39 시스템. ElementType) +408 System.Web.mvc .defaultModelBinder.BindComplexModel (ControlLerConText ControlLerContext, ModelBindingContext BindingContext) +756 System.Web.mvc.defaultModelBinder.bindModel (ControlLerConText ControlLeConText, ModelBindingContext BondingContext) +345 Sharparchb.wewelb.ModBindB.WeaMODB.MODBONDERB. Model (ControlLerConText ControlLerContext, ModelBindingContext BindingContext) +39 시스템 .web.mvc.defaultModelBinder.BindProperty (ControlLerConText ControlLerContext, ModelBindingContext BindingContext, PropertyDescriptor PropertyDescriptor) +231 SharParch.web.modelBinder.SharpModelBinder.SharpModelBinder.BindProperty (ControlLerContext, ModelContext, BINGCONTETTONTETTONTETTONTETCONTETCONTETCONTETCONTETCONTET, escriptor) +225 System.Web.MVC.DefaultModelBinder.BindProperties (ControllerContext controllerContext, ModelBindingContext bindingContext) +125 System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(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, ModelBindingText) +39 시스템. ParametErvalue (ControlleRconText ControlLerContext, ParameterDescriptor ParameterDescriptor) +219 System.Web.mvc.controllerActionInvoker.getParametErvalues ​​(ControlLerConText ControlLerContext, ActionDescriptor ActionDescriptor) +109 System.Web.mvc.controllerActionInvoker.inVokeaction (ControlLerConText ControlLerContext, String AcceMName) +399 System.Web.MVC.MVC.MVC.MVC.CONTROLCORORE 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. httpcontext) +151 System.web.mvc.mvchandler.processRequest (httpContext httpContext) +57 System.Web.mvc.mvchandler.system.web.ihttphandler.processRequest (httpcontext httpcontext) +7 System.wectortictext. em.web. httpapplication.iexecutionStep.execute () +181 System.Web.httPapplication.executestep (executionStep Step, Boolean & completedSynchronously) +75

도움이 되었습니까?

해결책

날카로운 아키텍처 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" 메서드가 호출되면 반복되는 동일한 개체인 엔터티Collection이 수정됩니다.그런 다음 예외가 발생합니다.

해당 코드 블록에 주석을 달거나 삭제하면 코드가 실행됩니다.

다른 팁

이 코드 블록이 S#ARP의 다른 기능에 영향을 미치나요?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top