Problems in Object Reference not defined for an object instance

Asked

Viewed 102 times

0

I have a problem with the result of the method SaveChanges().

I am trying to save a record, and it is persisted in the database, however the application is returning the message from exception:

{"Undefined object reference for an object instance."}

Applicationservice:

try
{
  using (TransactionScope transactionScope = Transactional.ExtractTransactional(this.TransactionalMaps))
  {
      if (distribuicaoAdmin.ID == 0)
      {
          this._DistribuicaoAdminService.Add(distribuicaoAdmin);
      }
      else
      {
          this._DistribuicaoAdminService.Update(distribuicaoAdmin);   
      }

      this.SaveChanges(transactionScope);
  }
}
catch (Exception ex)
{
  resultado = "Não foi possível inserir o registro.";
  this._SysLogService.Registrar(ex.Message + ex.StackTrace);
  return false;
}

When he enters the method this.SaveChages(transactionScope); is where the exception.

Object:

inserir a descrição da imagem aqui

One thing I noticed, after the data is persisted, my related objects come back with null value. My other objects are:

  1. Entity;
  2. detachment;
  3. distribution;
  4. tariff;

Edit 1:

Savechanges Methods:

public int SaveChanges(TransactionScope transactionScope)
{
    try
    {
        var changes = this._ServiceBase.SaveChanges();

        transactionScope.Complete();

        return changes;
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

The error is in the excerpt transactionScope.Complete();.

  • what is inside the Savechanges ? method in Stacktrace of Exception, checks which line occurs the problem

  • I did an Edit on the question of where the problem comes from. In this Complete() method I can no longer advance: "The symbol no implementations."

  • 1

    it is possible that transactionScope is null then. The problem comes from Transactional.ExtractTransactional but I do not know what the implementation of this.

  • I managed to resolve with [Transactional] on the implementation, but now is not saving more kkkk

  • now is not giving the commit so hehe

  • pq vc ta using this transaction scope?

  • Put what Transactional.Extracttransactional(this.Transactionalmaps) does inside pq as you said you have a problem with the transaction, it may be that the problem is there

Show 2 more comments

1 answer

0

Try making transactionScope?.Complete();. This way only the complete will be done if a Scope transaction is passed.

It can also be interesting to put a transaction rollback on the catch. This way, if any exception is returned, the transaction would be reversed, avoiding a partial update.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.