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

发布于 2024-11-24 19:18:35 字数 6620 浏览 1 评论 0原文

我对使用 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.config。 描述:执行当前 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.config 文件确实在项目中,它也是生成的,并且我已经验证它确实存在。

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

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

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

I'm having weird issues with code generated with netTiers. I've tried to use the framework provided in a simple form to save information on one of the entities created.

Here is the method I'm calling from an ASPX page:

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

When I call that method from a button click on the aspx page, i get the following exception information:

Server Error in '/' Application.
The configuration file entlib.config could not be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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 

The following method seems to be the one that is causing the exception:

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

Now, here is the weirdest thing. I put breakpoints in to trace through and find the issue. I hit F5 in my browser, and there was no exception error. After some trial and error, I've found that I get this exception error every time I submit the form, but if I hit F5, it resubmits fine without error, and the update does happen in the database. It would be greatly appreciated if someone could advise as to why this would be happening and what I can do to fix this error. The entlib.config file is indeed in the project, It was generated as well, and I've verified that it does actually exist.

The information on the EntLib that is being called with the ValidationIntegrationHelper is:

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

UPDATE: I still haven't been able to figure out how to fix this, so I did a terrible thing, I put a try/catch block around the code in DoValidate, so that it won't blow up on me. I needed to get this not to break while the clients are using it, but I still need to figure out why it is doing this, and fix it, instead of ignoring it before we are into production. If it just handles validation, then I can handle ignoring it, because I'm validating on the front side before saving or updating the entities.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走过海棠暮 2024-12-01 19:18:35

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

The issue seems to be just in the Enterpise Library validation. I regenerated the project with NetTiers validation and I don't have the issue. I wasn't able to figure out what the issue was, but generating the project with the NetTiers validation made the problem go away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文