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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:46:53+00:00 2026-05-23T15:46:53+00:00

Since beginning to use Code Contracts (.NET 4.0, VS2010 Ultimate & Premium) we have

  • 0

Since beginning to use Code Contracts (.NET 4.0, VS2010 Ultimate & Premium) we have encountered a strange problem in the debugger windows.

I have a simple solution with one executable, one library that uses Code Contracts, and one library that doesn’t. Each library contains one class and in the constructor of the class it initializes a list of integers. If we place a breakpoint after the list is initialized and look at it in the debugger windows (including the immediate window) we can see the values just fine. However, if we try to cast the value to its explicit type it breaks.

In the libraries that are not using Code Contracts the following works in the debugger windows:

(List<int>)nums

In the libraries that are using Code Contracts this generates “The type or namespace ‘List’ is not valid in this scope’. We have to do the following to get it to work:

(System.Collections.Generic.List<int>)nums

Please note that the code works fine, no issues there, the problem is only in the debugger windows.

UPDATE: The only setting that seems to have an effect is the check-box next to “Perform Runtime Contract Checking” on the “Code Contracts” tab in the project properties. After looking at the code in ILSpy, I found an attribute added to assemblyinfo.cs, an attribute (RuntimeContractsAttribute), and an enum (RuntimeContractsFlags), added to my project. On a whim, I copied the code for these items from ILSpy and created my own version. Now, everything works. But, when I select “Build” a contract reference assembly, the build fails. (I assume that the reference generator is trying to add the compiler generated code, and bombs cause I added it manually.) However, without adding the Runtime code manually, the debugger still fails regardless of the Build Contract Reference Assembly setting.

  • 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-23T15:46:54+00:00Added an answer on May 23, 2026 at 3:46 pm

    The difference between the two libraries that matters is not whether or not they are using the Code Contracts library, but rather whether you have a using System.Collections.Generic; statement in the code file in which the debugger is breaked on.

    The Visual Studio debugger does its best to evaluate expressions as if you were to write that expression on the line of code in which you are breaking on, and that includes respecting the lexical scope of that line of code; if you were to try to cast to List<int> in a file that doesn’t have a using System.Collections.Generic;, that would fail with an error, too.

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

Sidebar

Related Questions

Since beginning to use VB.NET some years ago I have become slowly familiar with
This problem has been bugging me since forever. I have an array and in
Since CS3 doesn't have a web service component, as previous versions had, is there
Since Graduating from a very small school in 2006 with a badly shaped &
Since the keyboard is the interface we use to the computer, I've always thought
I have a very beginning C# question. Suppose I have a class called GameObject
I ve been using hxt with no problem, but there was a problem since
since i'm at the beginning with Android coding i hesitated to post my question,
This is the beginning -- I have a file on disk which is HTML
I have some fundamental points/questions about OpenGL, not all involving code but concepts as

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.