Problem with CslaActionExtender when first saving doesn't succeed.

Problem with CslaActionExtender when first saving doesn't succeed.

Old forum URL: forums.lhotka.net/forums/t/7097.aspx


alef posted on Saturday, June 13, 2009

When using the CslaActionExtender  there exists the following problem.

Take the following actions:

Show a form to edit for example a customer object.

Stop SQL Server to simulate an error.

Click on the OK button of the Customer form.

An error will be raised to say that no connection to SQL Server can be done.

Until now the behavior is as expected.

Start SQL Server again.

Try again to click on the OK button.

We get the following error:

System.InvalidCastException: The underlying data source does not cast to a CSLA BusinessBase object

This behavior is not as expected because the save should work now.

 

The problem is that the data source is empty. In case of an error you should call _bindingSourceTree.Bind(savableObject) no matter what PostSaveAction you have. Even in the case AndClose you should rebind the datasource so the user can try again to save the object.

Below follows the code of CslaActionExtender  with an added line of code which solves the problem in my opinion.

Lhotka : can you have a look at this suggestion?

protected void OnClick(object sender, System.EventArgs e)

.....

try

{

savableObject = savableObject.Save() as Csla.Core.ISavable;

...

}

catch (Exception ex)

{

_bindingSourceTree.Bind(savableObject); //by adding this line of code it solves the problem

OnErrorEncountered(new ErrorEncounteredEventArgs(props.CommandName, new ObjectSaveException(ex)));

raiseClicked = false;

}

 

alef replied on Thursday, June 18, 2009

In the ProjectTracker example the CslaActionExtender is not used. It is using helper methods. But the same problem exists.
So in place of calling RebindUI(true, false) it is better to call RebindUI(true, true).
See code below

   private void OKButton_Click(object sender, EventArgs e)
    {
      try
      {
        using (StatusBusy busy = new StatusBusy("Saving..."))
        {
          //RebindUI(true, false);
          //In case of failure we have to rebind ==> so above line is put in comment and next line is put in place
          RebindUI(true, true);
        }
        this.Close();
      }
    ...

alef replied on Tuesday, June 23, 2009

Is it clear what I try to explain?

RockfordLhotka replied on Tuesday, June 23, 2009

I think so. I've added an entry in the bug tracker

http://www.lhotka.net/cslabugs/edit_bug.aspx?id=426

alef replied on Friday, March 26, 2010

Any date foreseen to fix this bug?

RockfordLhotka replied on Friday, March 26, 2010

I know that Miguel has been doing a lot of travel over the past several months and has little or no time to work on CSLA. In these economic times paying work comes before volunteer efforts for most people.

fordeath21 replied on Monday, March 17, 2014

same question in csla 3.8.4.

tiago replied on Wednesday, March 19, 2014

HI

There was a new release of CslaContrib that fixed all known bugs on CslaActionExtender.

Copyright (c) Marimer LLC