CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Error in method InitializeBusinessRules in Csla.Core.BusinessBase

rated by 0 users
Answered (Verified) This post has 1 verified answer | 1 Reply | 2 Followers

Not Ranked
3 Posts
eduardo.micromust posted on Tue, Jul 31 2012 3:15 PM

InitializeBusinessRules is marking the rules as Initialized before it is really initialized.

If a second thread reaches this method while the first thread is still loading the rules, you´ll get a error. To correct this error is necessary to put the line "rules.Initialized = true;" after "AddBusinessRules();":

    private void InitializeBusinessRules()

    {

      var rules = BusinessRuleManager.GetRulesForType(this.GetType());

      if (!rules.Initialized)

        lock (rules)

          if (!rules.Initialized)

          {

           rules.Initialized = true;

            try

            {

              AddBusinessRules();

            }

            catch (Exception)

            {

              BusinessRuleManager.CleanupRulesForType(this.GetType());

              throw;  // and rethrow exception

            }

            rules.Initialized = true;

          }

    }

Answered (Verified) Verified Answer

Top 10 Contributor
9,282 Posts

Thank you for finding this issue, I'll fix it in 4.3 and 4.5.

Rocky

Page 1 of 1 (2 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems