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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:10:00+00:00 2026-05-16T11:10:00+00:00

This one is sort of esoteric. I ran into a NullReferenceException while trying to

  • 0

This one is sort of esoteric. I ran into a NullReferenceException while trying to open a form (in the winforms designer) in a winforms project in visual studio 2008. The stack trace points to the fourth line of the following code:

public static class Logger
{
    public static void LogMethodEnter()
    {
        var frame = new StackFrame(1);
        var method = frame.GetMethod();
        Trace.TraceInformation("{0}.{1}.{2}()", method.DeclaringType.Namespace, method.DeclaringType.Name, method.Name);
        Trace.Indent();
    }

    public static void LogMethodExit()
    {
        Trace.Unindent();
    }
}

…meaning the line with the opening curly brace. I’ve run into the same issue (but not involving the winforms designer) on other projects, and I think it was a threading related issue, but I don’t have the code to replicate it.

Why does this happen and why does the exception stack trace point to the line with the curly brace?

Clarification: The null reference exception only happens in the winforms designer. When the application is run, it doesn’t throw that error.

  • 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-16T11:10:01+00:00Added an answer on May 16, 2026 at 11:10 am

    I’m guessing that the line numbers are off (the actual reason for that is not as important) and the exception is actually thrown by this expression:

    method.DeclaringType.Namespace
    

    And the reason you might see a NullReference exception there is because the new StackFrame(1) expression a couple lines previous can sometimes return an empty frame. An empty frame means the call to .GetMethod() will return null, and there you go.

    The reason you sometimes get an empty frame is that the just-in-time compiler can choose to inline short, repeatedly-called methods like the one in your code. That will throw off your call stack so at best you get a higher-level method than you intended, or at worst (in your Main method) there is no higher method and you get null.

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

Sidebar

Related Questions

Been trying to sort this one out for a while. I'd really appreciate any
I am new to LINQ and am trying to sort this one out. I
Okay I have spent the last 2 days trying to sort this one out.
James here. This question relates (sort of) to the one I posted a little
This one has been stumping me for a while. But I'm no expert. This
Been kind of stuck on this one for a while now, so any help
hopefully there's an easy solution to this one. I have my MVC2 project which
I was trying to make a sort of loading bar, I've made this but
So this one is sort of a language agnostic question that I don't really
My issue is very similar to this one: XSLT: use parameters in xls:sort attributes

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.