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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:16:11+00:00 2026-05-17T15:16:11+00:00

Today something peculiar happened while debugging in VS 2008. I will give the small

  • 0

Today something peculiar happened while debugging in VS 2008. I will give the small code snippet

List<IPageHandler> myPageList = TaskSOM.PageList;

if( myPageList != null && myPageList.Count > 0 )
{
     PageHandler aPage = myPageList[0] as PageHandler;
     ...; // Some more code below  
}

While running the application the typecast failed and aPage became null (That was the reason for debugging). So all the code that was using that vaiable failed. But during debug the first element in the myPageList was in deed a PageHandler. When I execute the line in immediate window

  PageHandler aPage = myPageList[0] as PageHandler;

aPage variable has proper value. But If move the debugger to that line and execute I get a null. Due to confidentiality I couldn’t share the whole code. But has anyone faced such an issue with the immediate window in the past. Is there any material regarding how the immediate window works.

  • 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-17T15:16:12+00:00Added an answer on May 17, 2026 at 3:16 pm

    This would be a very good example of code where you don’t want to use the as operator. Clearly you cannot afford the cast to fail or you would have included a null test and did something meaningful if the cast failed.

    Use a real cast. You’ll get an informative exception that gives you a much better hint why the cast failed:

     PageHandler aPage = (PageHandler)myPageList[0];
    

    Exceptions are your friend, don’t avoid them. Taking a wild guess: this could happen when you use a COM object in a thread and the COM server doesn’t support marshaling. If that’s the case then the exception message will tell you so.

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

Sidebar

Related Questions

Today while writing some Visual C++ code I have come across something which has
Today I discovered something that makes me sad: objects of type System.Generic.Collections.List don't have
Today I implemented a small piece of code that include analytics only in production
Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring
Today when I was in computer organization class, teacher talked about something interesting to
Today I had a coworker suggest I refactor my code to use a label
Today at work we came across the following code (some of you might recognize
I noticed something weird today I would like explained. I wasn't 100% sure how
It's only started doing this today, so I assumed it was something I've done,
today I have deployed my first MVC 2 application on Windows Server 2008, and

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.