System.Nullreferenceexception was unhandled by user code

Asked

Viewed 77 times

-1

When compiling my application I received this error from the image below, would anyone know how I could solve?

  • You are trying to access the method of a null object. Check if you have prompted it correctly.

  • Diego, thank you. i added this line /Process = aplProcesso.consultarPorNProcessoERTeste(new Nhibernatehelper().Test().Opensession(), ""); and it works, without giving the error, however, that way it would be grotesque on my part, there is a way for me to enter my thread with my current session as I created another test.

  • Thank you so much for contributing tips, I managed to solve brother.

1 answer

0


"Check to determine if the Object is null before Calling the method". The program itself answers your question.

Your method tries to return a session without at least checking if there is an initialized instance, that is, without even knowing whether a session has been created or not. You need to perform an exception check and, only if there is a session, then return it.

  • Marcos, I changed here and put Process = aplProcesses.consultarNProcessoTeste(new Nhibernatehelper().Test().Opensession(), ""); it works, but it would be a grotesque way, I wanted to see a way to call my session to inject my thread.

  • This is a huge message chain, avoid it as much as possible. You could not use Try/Catch blocks to check if the session has already been initialized?

  • 1

    I managed to solve brother, thanks for the tips

Browser other questions tagged

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