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

  • Home
  • SEARCH
  • 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 6662283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:22:24+00:00 2026-05-26T02:22:24+00:00

This code throwing out an error: bool status1 = (bool)Cache[cache_req_head]; bool status2 = (bool)Cache[cache_super];

  • 0

This code throwing out an error:

    bool status1 = (bool)Cache["cache_req_head"];
    bool status2 = (bool)Cache["cache_super"];
    bool status3 = (bool)Cache["cache_head"];

This is how the cache variables were set:

if (checkreqhead == true)
        {
            Cache["cache_req_head"] = true;
        }
        else if (checksuper == true)
        {
            Cache["cache_super"] = true;
        }
        else if (checkhead == true)
        {
            Cache["cache_head"] = true;
        }

Coming from PHP background, this is awkward. The error is:

Object reference not set to an instance of an object

I’m certain it is something really simple, but probably I can’t spot it.

THANKS ALL FOR HELPING 🙂

  • 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-05-26T02:22:24+00:00Added an answer on May 26, 2026 at 2:22 am

    “Object reference not set to an instance of an object” is c# lingo for “you did something stupid with a null value”

    If the Cache is empty you need to check that first

    bool status1 = (bool)Cache["cache_req_head"];
    

    should be

    bool status1 = false;
    if (Cache["cache_req_head"] != null)
    {
       status1 = (bool)Cache["cache_req_head"];
    }
    

    This is an effect of the fact that value types (like bool, int, etc) in c# can not be null. There is a wrapper, Nullable<T> with the shorthand T? that you can use if you want to allow null values for the value types.

    You can cast your value to a bool? since that allows for null.

    bool? status1 = (bool?)Cache["cache_req_head"];
    

    You can then check status1 == null or status1.HasValue, to get the actual bool value you need to pick it out with status1.Value. If you pick status1.Value while status1 == null you will get a runtime exception like the one you just got.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

why is this code throwing an out of memory error, when there is only
The following code is throwing the error this.element is null. However, the wid_cont is
Why is this code throwing up a SIGSEGV : int main() { unsigned long
I've seen the code examples on this article , but throwing Controller_Exception_404 produces an
While running my program I get this error: terminate called after throwing an instance
I am getting this error on a remote server, but the same code executes
I cannot for the heck of it find why this is throwing an error!
While executing the following code szNotes := SQL.FieldByName('Notes').AsString; throwing an fetch type out of
I'm working on someone else's code, and it's throwing an error that 'InputStreamError' is
I am running a piece of code that is throwing an error in eclipse.

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.