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 1047975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:23:03+00:00 2026-05-16T16:23:03+00:00

Ever since I started programming this question has been annoying me, not where is

  • 0

Ever since I started programming this question has been annoying me, not “where is my code null” but specifically is there any way to get the type of the object that is null from the exception?

Failing that, can anyone provide a blog post or msdn article that explains the reason why the .NET Framework doesn’t (or can’t) provide these details?

  • 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-16T16:23:04+00:00Added an answer on May 16, 2026 at 4:23 pm

    Um… Because it’s null.

    In C#, a reference type is a pointer to something. A null pointer isn’t pointing to anything. You are asking, “What type of thing would this point to if it was pointing to something”. That’s sort of like getting a blank sheet of paper, and asking, “What would this say if it had something written on it?”

    UPDATE: If the framework can’t know the type of a null pointer, can’t it know what type it’s supposed to be? Well, it might. Then again, it might not. Consider:

     MyClass myobj = null;
     int hash = myobj.GetHashCode();
    

    Unless you overrode it in MyClass, GetHashCode is defined in System.Object. Should you get a complaint that myobj needs to be a System.Object? Now, when we check ourselves, we’re completely free to specify the required type.

      SomeFunc(MyClass myparam)
      {
           if (myparam == null)
               throw new ArgumentNullException("myparam must be a MyClass object");
      }
    

    But now we are talking about application code, not CLR code. Which makes you “real” question “Why don’t people write more informative exception messages?”, which is, as we say here at SO “subjective and argumentative“

    So, you basically want the system level exception to know the type information which is only known at the applications level, which we’d need so way to communicate. Something like:

      SomeFunc(MyClass myparam)
      {
           if (myparam == null)
               throw new ArgumentNullException("myparam", typeof(MyClass));
      }
    

    But that’s not really buying us much, and if you really want it, you could write it yourself:

      public class MyArgumentNullException : ArgumentNullException
      {
          public MyArgumentNullException(string name, Type type) 
              :base(name + "must be a " + type.Name + " object");
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ever since I started programming this has been something I have been curious about.
This question has been on my mind ever since I started with iOS development:
This has been bugging me ever since I started learning Ruby five months ago:
Ever since .net 2.0 release this question has been discussed over a large number
I've been a Microsoft developer ever since I started programming... I started out by
I've gone rounds with this ever since I started programming classic ASP 12 (or
I've been wondering this ever since I started using MS's control templates examples as
Greetings all, This has confused me ever since I first started coding in C#.
Ever since I started using Xcode, I've experienced extremely annoying problems with Code Sense
Ever since I created this Rails 3.2.3 project to use MiniTest, I have been

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.