Transaction.RollBack() Error: Oject reference not set an instance of an object

Hello,

I am trying to do a Transaction Rollback in a Removing Rule, for instance:

public override void ElementRemoving(Microsoft.VisualStudio.Modeling.ElementRemovingEventArgs e)

{

e.ModelElement.TransactionManager.CurrentTransaction.Rollback();

}

And I had an "object reference not set an instance of an object" error...

What am I doing wrong

Thanks a lot.

Rafa Cabedo.


Answer this question

Transaction.RollBack() Error: Oject reference not set an instance of an object

  • GOKU

    Rafa,

    I don't know, but I get the same result ;-)

    Depending on exactly what you want to achieve, you could either:

    1) throw an exception, which will abort the transaction, or

    2) use Rollback in a "RemoveRule", which doesn't cause the exception.

    I'd guess you are getting an exception from the RemovingRule because other methods are called on the model element after the rule has fired (e.g. CreateRemoveCommand and OnRemove). However, the CurrentTransaction is null at this point. Still, I wouldn't expect it cause an exception.

    Cheers, Duncan


  • Vegemite

    Hello DuncanP,

    throw an exception works perfectly!!!

    Thank you very much!!!


  • Transaction.RollBack() Error: Oject reference not set an instance of an object