Link to home
Start Free TrialLog in
Avatar of ajaymaster143
ajaymaster143

asked on

nullreferenceexception was unhandled by user code

i get this error on

Exception ex = Server.GetLastError();
    if (ex.InnerException != null ) ex = ex.InnerException;

i don't understand why this error come.

   
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you checked that Server.GetLastError() is actually returning a valid object?
Avatar of ajaymaster143
ajaymaster143

ASKER

it's return null value.
ASKER CERTIFIED SOLUTION
Avatar of Asim Nazir
Asim Nazir
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The that is why you are getting a Null reference then. You are checking ex.InnerException without first checking that ex itself isn't null.
Even this will work:
if(ex != null )
{
// process
}

try this

string ex = Server.GetLastError().ToString();