سؤال

أنا تلقي خطأ من SharpArchitecture نموذج الموثق."جمع تعديله ؛ عملية التعداد قد لا تنفيذ." (تتبع المكدس في الأسفل).

بلدي MVC صفحات لإنشاء وتحرير بلدي SettingsModel رمي الخطأ.بدأ هذا يحدث عندما تتم ترقية إلى الإصدار S#arp العمارة 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:جمع تعديله ؛ عملية التعداد قد لا تنفيذ.] النظام.ThrowHelper.ThrowInvalidOperationException(ExceptionResource الموارد) +51 النظام.مجموعات.Generic.العداد.MoveNextRare() +7661017 النظام.مجموعات.Generic.العداد.MoveNext() +61 SharpArch.ويب.ModelBinder.SharpModelBinder.SetEntityCollectionProperty(ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor ، وجوه القيمة) +358 SharpArch.ويب.ModelBinder.SharpModelBinder.SetProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor ، وجوه القيمة) +61 النظام.ويب.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +265 SharpArch.ويب.ModelBinder.SharpModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +225 النظام.ويب.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +125 النظام.ويب.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, نموذج كائن) +293 النظام.ويب.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +772 النظام.ويب.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +345 SharpArch.ويب.ModelBinder.SharpModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +39 النظام.ويب.Mvc.DefaultModelBinder.UpdateCollection(ControllerContext controllerContext, ModelBindingContext bindingContext اكتب elementType) +408 النظام.ويب.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +756 النظام.ويب.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +345 SharpArch.ويب.ModelBinder.SharpModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +39 النظام.ويب.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +231 SharpArch.ويب.ModelBinder.SharpModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +225 النظام.ويب.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +125 النظام.ويب.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, نموذج كائن) +293 النظام.ويب.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +772 النظام.ويب.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +345 SharpArch.ويب.ModelBinder.SharpModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +39 النظام.ويب.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +219 النظام.ويب.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +109 النظام.ويب.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext ، سلسلة actionName) +399 النظام.ويب.Mvc.تحكم.ExecuteCore() +126 النظام.ويب.Mvc.ControllerBase.تنفيذ(RequestContext requestContext) +27 النظام.ويب.Mvc.ControllerBase.النظام.ويب.Mvc.IController.تنفيذ(RequestContext requestContext) +7 النظام.ويب.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +151 النظام.ويب.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57 النظام.ويب.Mvc.MvcHandler.النظام.ويب.IHttpHandler.ProcessRequest(HttpContext httpContext) +7 النظام.ويب.CallHandlerExecutionStep.النظام.ويب.HttpApplication.IExecutionStep.تنفيذ() +181 النظام.ويب.HttpApplication.ExecuteStep(IExecutionStep خطوة منطقية& completedSynchronously) +75

هل كانت مفيدة؟

المحلول

يبدو أن هناك خلل في حاد العمارة 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 هو المعدل الذي هو نفس الكائن الذي يتم يتحرك.ثم يتم طرح استثناء.

تعليق أو حذف رمز كتلة التعليمات البرمجية الخاصة بك يجب أن تعمل.

نصائح أخرى

لا تعليق هذا كتلة من التعليمات البرمجية تؤثر على وظائف أخرى من S#arp ؟

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top