Instance error

Asked

Viewed 36 times

-1

I’m getting the following error:

Referência de objeto não definida para uma instância de um objeto.

The line generating the error is as follows:

var _TceView = MapperFacade.MapperConfiguration.Map<TceView>(await _TceRepositorio.buscarTce(pIdTce));

What’s the problem? I’ve fucked up the whole code and I can’t find it.

  • To Referência de objeto não definida para uma instância de um objeto occurs when you try to do something on an object nulo. Looking at your code I believe that the _TceRepositorio.buscarTce(pIdTce)is not returned a record, and the MapperFacade.MapperConfiguration.Map<TceView>while trying to make TceView.Campogives the error in question.

  • or the very _TceRepositorio was not instantiated

1 answer

1

Check the return of the method _TceRepositorio.buscarTce(pIdTce). It must be returning a null value. Below is an approach that facilitates its verification:

var testObject = await _TceRepositorio.buscarTce(pIdTce);

// Coloque um breakpoint neste ponto e verifique se o testObject está nulo, 
// isto deve estar causando o seu erro, caso esteja chegando um valor nulo, 
// implemente verificações no código para tratar situações como esta.
var _TceView = MapperFacade.MapperConfiguration.Map<TceView>(testObject);

Better validate your business rule to identify if the object returned by the method buscarTce() may or may not work with null values.

  • I did this but it is bringing the object yes, I keep getting the same error when it reaches the line: var _Tceview = Mapperfacade.MapperConfiguration.Map<Tceview>(testObject);

  • @Joãoignácio, then what may be happening is some property of the Tceview object that is coming null and the class does not accept null.

  • 1

    What happened was that at the start of the application the automapper class was not being instantiated so the mapping was not happening, I made the change and the application ran normally.

Browser other questions tagged

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