Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7931137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:38:05+00:00 2026-06-03T20:38:05+00:00

How do I handle NullReferenceException for the below statement as I get null exception

  • 0

How do I handle NullReferenceException for the below statement as I get null exception error for the below statement if it is not present in the query string when using URL Routing

string lang = RouteData.Values["Language"].ToString();

Error Details

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:

System.NullReferenceException: Object reference not set to an instance of an object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:38:06+00:00Added an answer on June 3, 2026 at 8:38 pm

    You are getting this exception because RouteDate.Values[“Language”] is null and you are applying instance method .ToString on it.
    just add an if to check for null

    string lang="";
    if(RouteData.Values["Language"] != null)
          lang = RouteData.Values["Language"].ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I handle poison messages when not using WCF? The code below creates
To handle viewExpiredException in JSF, I coded <error-page> <exception-type>javax.faces.application.ViewExpiredException</exception-type> <location>/error.html</location> </error-page> <session-config> <session-timeout>1</session-timeout> </session-config>
I get a NullReferenceException was unhandled by user code error with the following code
I need some help with my program. I get this error when I run
Why would my try-catch block still be throwing an error when it's handled? Exception
I'm trying to add ConfirmDialogHandler to dialog handler and i get NullReferenceException. This happens
If an exception is thrown in IEditableObject.EndEdit (when set from the WPF Datagrid using
I am trying to implement Error handling using Action Filters Attributes as per ScottGu's
SUMMARY: When browsing an ASP.NET website using Windows Explorer, popup windows do not borrow
Can anyone tell me How do I solve this error. Error: NullReferenceException was Unhandled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.