在nettier生成的代码中出现奇怪的异常错误

本文关键字:错误 异常 nettier 代码 | 更新日期: 2023-09-27 18:02:49

我有奇怪的问题与netTiers生成的代码。我已经尝试使用框架提供了一个简单的形式来保存创建的实体之一的信息。

这是我从ASPX页面调用的方法:

    public void UpdateSupplier(Object sender, EventArgs e)
    {
        // Update Supplier name and code from update form
        supplier.Name = txtName.Text;
        supplier.Code = txtCode.Text;
        // Save the Changes - Exception happens on next line!
        PPGEDI.Data.DataRepository.SuppliersEntityEntityProvider.Save(supplier);
        // Reload the information from the database to display
        ReLoadInformation();
    }

当我从aspx页面上的按钮点击调用该方法时,我得到以下异常信息:

'/'应用程序中的服务器错误。配置文件entlib. conf。找不到配置。描述:在执行当前web请求期间发生了未处理的异常。请查看堆栈跟踪以获得有关错误及其在代码中的起源的更多信息。

Exception Details: System.IO.FileNotFoundException: The configuration file entlib.config could not be found.
Source Error:
Line 190:       public override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
Line 191:       {
Line 192:           Validator validator = new ValidationIntegrationHelper(this).GetValidator();
Line 193:
Line 194:           if (validator != null)

Source File: PPGEDI.Entities'Validation'PropertyValidator.cs    Line: 192
Stack Trace:
[FileNotFoundException: The configuration file entlib.config could not be found.]
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource.GetRootedCurrentConfigurationFile(String configurationFile) +221
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource..ctor(String configurationFilepath, Boolean refresh, Int32 refreshInterval) +45
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource..ctor(String configurationFilepath, Boolean refresh) +48
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource..ctor(String configurationFilepath) +39
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSourceElement.CreateSource() +64
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceFactory.Create(String name) +355
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceFactory.Create() +96
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer() +25
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet() +84
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current() +22
   Microsoft.Practices.EnterpriseLibrary.Validation.ValidationFactory.get_DefaultCompositeValidatorFactory() +25
   Microsoft.Practices.EnterpriseLibrary.Validation.PropertyValidationFactory.GetPropertyValidatorFromAttributes(Type type, PropertyInfo propertyInfo, String ruleset, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory) +166
   Microsoft.Practices.EnterpriseLibrary.Validation.PropertyValidationFactory.GetPropertyValidator(Type type, PropertyInfo propertyInfo, String ruleset, ValidationSpecificationSource validationSpecificationSource, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory) +264
   Microsoft.Practices.EnterpriseLibrary.Validation.PropertyValidationFactory.GetPropertyValidator(Type type, PropertyInfo propertyInfo, String ruleset, ValidationSpecificationSource validationSpecificationSource, MemberValueAccessBuilder memberValueAccessBuilder) +71
   Microsoft.Practices.EnterpriseLibrary.Validation.Integration.ValidationIntegrationHelper.GetValidator() +106
   PPGEDI.Entities.Validation.PropertyValidator.DoValidate(Object objectToValidate, Object currentTarget, String key, ValidationResults validationResults) in PPGEDI.Entities'Validation'PropertyValidator.cs:192
   Microsoft.Practices.EnterpriseLibrary.Validation.Validator.Validate(Object target) +80
   PPGEDI.Entities.EntityBaseCore.Validate(String propertyName) in PPGEDI.Entities'EntityBaseCore.generated.cs:477
   PPGEDI.Entities.EntityBaseCore.OnPropertyChanged(PropertyChangedEventArgs e) in PPGEDI.Entities'EntityBaseCore.generated.cs:342
   PPGEDI.Entities.EntityBaseCore.OnPropertyChanged(String propertyName) in PPGEDI.Entities'EntityBaseCore.generated.cs:329
   PPGEDI.Entities.SuppliersEntityBase.set_Name(String value) in SuppliersEntityBase.generated.cs:279
   PPGEDI.Supplier.Supplier_Main_Config.UpdateSupplier(Object sender, EventArgs e) in Supplier_Main_Config.aspx.cs:29
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225 

下面的方法似乎是导致异常的方法:

  /// <summary>
  /// Does the validate.
  /// </summary>
  /// <param name="objectToValidate">The object to validate.</param>
  /// <param name="currentTarget">The current target.</param>
  /// <param name="key">The key.</param>
  /// <param name="validationResults">The validation results.</param>
  public override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
  {
     // Exception Error on next line!!!
     Validator validator = new ValidationIntegrationHelper(this).GetValidator();
     if (validator != null)
     {
        ValidationResults results = validator.Validate(this);
        if (!results.IsValid)
        {
           validationResults.AddAllResults(results);
        }
     }
  }

现在,这是最奇怪的事情。我设置了断点来跟踪并找到问题。我在浏览器中按了F5,没有出现异常错误。经过一些尝试和错误,我发现每次提交表单时都会出现这个异常错误,但如果我按F5,它会重新提交,没有错误,并且更新确实发生在数据库中。如果有人能建议为什么会发生这种情况,我能做些什么来修复这个错误,我将不胜感激。entlib。配置文件确实在项目中,它也是生成的,并且我已经验证了它确实存在。

使用ValidationIntegrationHelper调用的EntLib的信息是:

Assembly Microsoft.Practices.EnterpriseLibrary.Validation.dll, v2.0.50727

更新:我还没能弄清楚如何解决这个问题,所以我做了一件可怕的事情,我在DoValidate的代码周围放了一个try/catch块,这样它就不会在我身上爆炸。我需要让它在客户端使用它时不会中断,但我仍然需要弄清楚为什么它会这样做,并修复它,而不是在我们投入生产之前忽略它。如果它只处理验证,那么我可以处理忽略它,因为我在保存或更新实体之前在前端进行验证。

在nettier生成的代码中出现奇怪的异常错误

问题似乎只是在企业库验证中。我用NetTiers验证重新生成了项目,我没有问题。我无法弄清楚问题是什么,但是用NetTiers验证生成项目使问题消失了。