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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:03:37+00:00 2026-05-12T18:03:37+00:00

Can IL produced by C# 4.0 compiler run on CLR 2.0? To clarify, I’m

  • 0

Can IL produced by C# 4.0 compiler run on CLR 2.0?

To clarify, I’m not asking about VS 2010 multi-targeting (where VS chooses the right compiler version), I want to know if csc.exe 4.0 supports multi-targeting…

  • 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-12T18:03:37+00:00Added an answer on May 12, 2026 at 6:03 pm

    If all else fails, try it. I’ve just tested the following in VS2010b2, compiled targeting 2.0:

    using System;    
    class Program {
        static void Main() {
            Write();
            Write(msg: "world");
            Console.ReadLine();
        }
        static void Write(string msg = "Hello") {
            Console.WriteLine(msg);
        }
    }
    

    This uses two new C# 4.0 language features, which use the meta-data that is also present in .NET 2.x/3.x/CLR 2; it executes fine on my regular (CLR 2) machine (my VS2010b2 is a VM). So I conclude “yes, for some features”. Obviously if you use a framework-dependent feature (dynamic, etc) it isn’t going to end so well.

    Edit: re your comment; I’ve tried csc at the command-line, and by default this does target CLR 4; I’ll try to see if I can get it to target CLR 2 (like VS obviously can). Unfortunately, it no longer includes the (faked, btw) command line in the build output window…

    Update: some “in the know” people came back with:

    Pass /nostdlib and a reference to the 2.0 mscorlib.dll.

    And sure enough:

    C:\Windows\Microsoft.NET\Framework\v4.0.21006>csc /nostdlib /reference:%SystemRo
    ot%\microsoft.net\framework\v2.0.50727\mscorlib.dll /out:c:\my.exe /target:exe "
    C:\Users\Marc\Documents\Visual Studio 2010\Projects\ConsoleApplication6\ConsoleA
    pplication6\program.cs"
    Microsoft (R) Visual C# 2010 Compiler version 4.0.21006.1
    Copyright (C) Microsoft Corporation. All rights reserved.
    

    works fine (exe works on my non-4.0 machine). Credit: Kevin Pilch-Bisson

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

Sidebar

Related Questions

Can a C++ compiler produce a not so good binary? You can think here
I encountered a warning produced when compiling my kernel module that I can't get
I'm trying to create a tool that can generate XSDs for the XAML produced
Can someone explain the following strange behavior? I run the following program on a
I have cucumber features working fine and rspec spec working fine i can run
I would like a standalone C++ compiler that doesn't need installing. Something that can
How would I go about creating an Xcode project for iOS that can be
Is there a tool available that can produce an HTML summary list of perl
I have reason to believe console.log and JSON.stringify can produce inconsistent views of the
I'm writing a small .NET application that can produce SWF files, and I need

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.