-1

When I am inputting wrong username and password this error shows

this is my code

RegLog reuser = res.ResultAs<RegLog>(); //database result <-- Error Occurs here.

any solution? I already tried to declare it as var but error still persist. Thank you.

S. Walker
  • 2,129
  • 12
  • 30
all123
  • 1
  • 1
  • 1
    It sounds like `res` is null. – Simon MᶜKenzie Nov 20 '21 at 02:27
  • Please provide additional information on how `res` is created. The only way this code would generate a null reference exception would be for `res` to be null, or for some code in `ResultAs` to actually be generating the exception. Not enough information. – S. Walker Nov 20 '21 at 02:31

1 Answers1

0

It is because for some reason (probably wrong username and password), the variable res is null.

Try to check a null reference before using res.

Example: if(res == null) { //do something }