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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:03:42+00:00 2026-05-30T08:03:42+00:00

I have .NET application that crashes with NullReferenceException. The funny thing is that the

  • 0

I have .NET application that crashes with NullReferenceException. The funny thing is that the log shows this:

Inner Exception System.NullReferenceException: Object reference not set to an instance of an object.
           at System.Object.GetType()

The thing that’s puzzling me is that the exception happens inside of GetType instead on the line that calls GetType. I’ve tested following situations.

If I call GetType on an object that is null, the exception happens on a line that’s calling GetType, not within GetType.
I also tried How can I get a NullReferenceException in this code sample? but strangely
I get the exception in Program.Main not within Object.GetType (although in that post it’s within GetType).

I also tried concurrently creating objects and calling GetType, but needlesly to say,
there is no window in creation of .net objects where GetType throws NullReferenceException.
The only thing that crosses my mind right now is that this was maybe behavior of some older .NET implementation.

So any idea how to cause NullReferenceException within GetType, and if you could provide proof of concept code I would be eternally grateful.
Thank you for your time.

  • 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-30T08:03:43+00:00Added an answer on May 30, 2026 at 8:03 am

    One way would be to call the GetType method (“on” a null-reference) with the call instruction rather than the with the callvirt instruction that C# normally uses. This will prevent the pre-method-call runtime null-check from occurring. Instead, the null-reference would be passed to the method, causing the exception to be thrown inside the method itself.

    For example, using the InvokeNonVirtual sample provided here, you can do:

    var method = typeof(object).GetMethod("GetType");
    object[] args = { null };
    
    InvokeNonVirtual(method, args);
    

    This produces a TargetInvocationException with the InnerException being a NullReferenceException having stack-trace:

    at System.Object.GetType()
    at NonVirtualInvoker(Object )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
Let's say I have a .NET application that crashes when I close it and
I have an application that is built using ASP.NET, with an embedded Silverlight Object
Here's the thing. My .NET application crashes with a pretty ugly general exception fault
I have an ASP.NET application that crashes when a null date value is returned.
I have a VB.NET application that crashes on a client's computer with a BSOD
I have a .NET application that is meant to be run on a local
I have a .NET application that processes around 300,000 records in a batch import,
I have a .NET application that I want to use as a client to
We have a .net application that we didn't develop, but use. I can tell

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.