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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.