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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:03:55+00:00 2026-06-05T05:03:55+00:00

I don’t know that the following piece of code is really relevant, but for

  • 0

I don’t know that the following piece of code is really relevant, but for the sake of full disclosure here is the code I was trying to call from the Immediate Window:

abstract class Test
{
    public int x;

    public Test()
    {
        x = 5; 
    }
}

class TestImp : Test
{
    public int GetX()
    {
        return this.x;
    }
}

It was just a test to see whether the default base constructor gets called automatically or if I have to call it specifically because I couldn’t remember.

Okay, on to the problem. I typed this into the Immediate Window to see the result:

new Mercury_Reports.TestImp().GetX();

And rather than evaluating the expression it just started my application. I closed the app and tried again two more times and got the same result. The next time, I went and put a breakpoint in my Program.cs file. Then instead of starting the app like it did the last three times and then hitting the breakpoint, it decided to actually just evaluate my expression.

I’ve seen some weird things in the Visual Studio IDE before, but I think this is one of the weirdest. Anyone have a clue as to what was going on there? 🙂

  • 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-05T05:03:56+00:00Added an answer on June 5, 2026 at 5:03 am

    When evaluating an expression in the immediate window when you’re not debugging the following process takes place

    • Loads your project / application binaries into the hosting process
    • Silently attaches the debugger to the hosting process
    • Evaluating the expression against that debugger session

    Most of the time this is done in a way that makes it hard to detect that the application is actually being run. But occasionally a side effect of the application shows through and reveals what’s really going on under the hood.

    EDIT

    In general it shouldn’t be displaying the UI though. I can think of some obscure corner cases where this would happen though and not be a Visual Studio bug. The basically all come down to the same scenario though

    The evaluated string causes an unintended side effect to happen at a time where it wouldn’t happen during normal program flow.

    This is actually more common than you’d expect in the immediate window because it’s essentially executing your code out of order. Normally you’d never get to new Mercury_Reports before executing Program.Main but in the immediate window this is exactly what happens. This can have nasty effects like re-ordering static type constructors

    Here are some unintended consequences which can surface via an immediate window expression

    • Cause types to be loaded and hence cause their static initializers to run
    • Change the order in which static initializers are run
    • The return type of the expression has a ToString method the debugger executes
    • The return type of the expression has a DebuggerDisplay value which the debugger executes

    In the past I have seen the static constructor case cause UI to show. Essentially a static type constructor was evaluating MainForm.Instance (a lazy creation property). During normal program flow it was called from Program.Main was run and from then on was simply available. In the immediate window though Program.Main didn’t run. But the expression being executed inadventently loaded that type and hence displayed the UI for what was a trivial property getter.

    This is a pretty obscure corner case though. I’d say the most likely cause here is a bug in Visual Studio. Debugging is nasty business, especially when executing live code, and this is probably a symptom of that.

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

Sidebar

Related Questions

don't know better title for this, but here's my code. I have class user
Don't know a better title but here is what im trying to do. I
don't know if the title describes anything about what I'm trying to say but
Don't really know how to formulate the title, but it should be pretty obvious
I don't know why, but this code worked for me a month ago... maybe
Don't know how to explain it better but i'm trying to get a response
Don't know if this is possible, but I have some code like this: val
Don't know if I'm over-thinking this or not.. but I'm trying to be able
Don't know how to frase this but I found this code wich works as
Don't know how to google for such, but is there a way to query

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.