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.

   
ajaymaster143Asked:
Who is Participating?
 
Asim NazirCommented:
Before accessing ex.InnerException, check if Ex is not null only then access innerexception of ex.
if(ex != null && ex.innerexception !=null)
{
// process
}

I hope it helps.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Have you checked that Server.GetLastError() is actually returning a valid object?
0
 
ajaymaster143Author Commented:
it's return null value.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Carl TawnSystems and Integration DeveloperCommented:
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.
0
 
Asim NazirCommented:
Even this will work:
if(ex != null )
{
// process
}

0
 
Pratima PharandeCommented:
try this

string ex = Server.GetLastError().ToString();
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.