.NET Framework 4.0 new features analyze

The Microsoft .NET Framework 4.0 is a software framework that can be installed on computers running Microsoft Windows operating systems. Current version is 4.0.30319.1 (4.0) / 12 April 2010; it is supported Windows 98 or later, Windows NT 4.0 or later. Programs written for the .NET Framework execute in a software environment that manages the program's runtime requirements. Also part of the .NET Framework, this runtime environment is known as the Common Language Runtime (CLR) and it is supported by Visual Studio 2010.

C# is a programming language that keeps evolving time by time. If we take a look in 2000, when C# is still a baby, it was just a simple, ordinary, and also for managed code language. And then, C# 2.0 introduced one of the most significant concept, the "Generics" that brought us more type-safety code, performance boost, and also looked more elegant. C# 3.0 is really a big revolution of this language with the most essential thing LINQ (Language Integrated Query). With LINQ, paradigm of C# itself become more like functional programming (not just ordinary imperative paradigm). This language begins it journey of becoming a multi-paradigm language. So, what comes next in C# 4.0 that is going to release with .NET 4.0 and Visual Studio 2010? It is "dynamic programming". Yes, it is a truth. I know that a lot of people (might / will argue) or (are arguing) it. Somebody thinks that the beauty of C# is about its strong-type, how come it become like "dynamic" (somebody calls it irregular style) one? They are disappointed or upset maybe. Somebody might happy and agree with its revolution, it becomes more and more rich. Well, it depends on how you look at it. I don't want to have the argument here.

.NET 4.0

The .NET Framework 4 introduces an improved security model, APIs, workflow models, inbuilt plug-in, workflow and VS designer for attracting to end-users. Here they added many new features and environment


New features:

  • Security Changes in the.NET Framework 4.
  • Application Compatibility and Deployment
  • Web
  • Client - Enhancements in WPF
  • Data
  • Communications and Workflow


Application Compatibility and Deployment
Security Changes in the.NET Framework 4: They implemented two significant changes in security the code that calls security policy APIs receives a NotSupportedException in addition to compiler warnings at run time, and also they invoked obsolete request permissions.
  • Machine-wide security policy
  • Security transparency

The .NET Framework 4 does not automatically use its version of the common language runtime to run applications that are built with earlier versions of the.NET Framework. To run old applications with.NET Framework 4, you must compile your application with the target.NET Framework version specified in the properties for your project in Visual Studio, or you can specify the supported runtime with the <supportedRuntime> Element in an application configuration file.

  • Diagnostics and Performance
  • Garbage Collection
  • Code Contracts
  • Design-Time-Only Interop Assemblies
  • Dynamic Language Runtime
  • Memory-Mapped Files

Features in Web:

  1. Web Forms controls, including a new Chart control.
  2. Microsoft Ajax, including additional support for client-based Ajax applications in the Microsoft Ajax Library.
  3. Multi-targeting, including better filtering for features that are not available in the target version of the.NET Framework.
  4. Web Forms, including more integrated support for ASP.NET routing, enhanced support for Web standards, updated browser support, new features for data controls, and new features for view state management.
  5. MVC, including new helper methods for views, support for partitioned MVC applications, and asynchronous controllers.
  6. Deployment, including new tools for automating typical deployment tasks.
  7. MVC, including new helper methods for views, support for partitioned MVC applications, and asynchronous controllers.

Enhancements in WPF:

  1. New Controls,
    1. DataGrid
    2. Calendar
    3. DatePicker
  2. Visual State Manager.
  3. Touch and Manipulation.
  4. Graphics and Animations,
    1. Layout Rounding
    2. Cached Composition
    3. Pixel Shader 3 Support
    4. Easing Functions
  5. Text,
    1. New Text Rendering Stack
    2. Selection and Caret Customization
  6. Binding,
    1. XAML Browser Applications
    2. HTML-XBAP Script Interop
    3. Full-Trust XBAP Deployment
  7. WPF and Windows.
  8. WPF and Silverlight Designer
    1. Improved Support for Silverlight.
    2. Support for Multiple Platform Versions.
    3. Visual Databinding.
    4. Auto Layout.
    5. Improved Property Editing.
    6. The Properties window now enables visually creating and editing Brush resources.


  1. ADO.NET
    1. Foreign Keys in the Conceptual Model.
    2. New Methods for N-Tier Application Development.
    3. EntityDataSource Support for the QueryExtender Control.
    4. Testability with IObjectSet<T>.
    5. Direct Execution of Store Commands
    6. Persistence-Ignorant Objects.
    7. Lazy Loading of Related Objects.
    8. Functions in LINQ to Entities Queries.
    9. OrderBy Improvements in LINQ to Entities.
    10. Customized Object-Layer Code Generation.
    11. Model-First Support.
    12. Complex Type Support.
    13. Naming Service.
    14. Improved Model Browser Functionality.
    15. Entity Designer Extensibility.
    16. Entity Data Model Documentation.
  2. Dynamic Data
    1. Automatic validation that is based on constraints that are defined in the data model.
    2. The ability to easily change the markup that is generated for fields in the GridView and DetailsView controls by using field templates that are part of a Dynamic Data project.

Communications and Workflow:

  1. WCF
    1. Configuration Based Activation.
    2. System.Web.Routing Integration.
    3. Multiple IIS Site Bindings Support.
    4. Routing Service.
    5. Support for WS-Discovery.
    6. Standard Endpoints.
    7. Workflow Services.
    8. Target Framework Attribute.
  2. WorkFlow
    1. Workflow Activity Model.
    2. Rich Composite Activity Options.
    3. Expanded Built-In Activity Library.
    4. Explicit Activity Data Model.
    5. Enhanced Hosting, Persistence, and Tracking Options.
    6. Easier Ability to Extend WF Designer Experience.
What is DLR in.NET 4.0 framework?

Due to DLR runtime, dynamic languages like ruby, python, JavaScript etc can integrate and run seamlessly with CLR. DLR thus helps to build the best experience for your favorite dynamic language. Your code becomes much cleaner and seamless while integrating with the dynamic languages. Integration with DLR is not limited to dynamic languages. You can also call MS office components in a much cleaner way by using COM interop binder. One of the significant advantages of DLR is that it provides one central and unified subsystem for dynamic language integration. 

C# 4.0 Language Innovation

  • Dynamically Typed Objects
  • Optional and Named Parameters
  • Improved COM Interoperability
  • Co and Contra variance

Dynamic types

What are the advantages and disadvantage of a dynamic keyword?

We all still remember how we talked bad about VB6 (Well I loved the language) variant keyword and we all appreciated how.NET brought in the compile time check feature, well so why are we changing now.  Well, bad developers will write bad code with the best programming language, and good developers will fly with the worst programming language. The dynamic keyword is an excellent tool to reduce complexity and it's a curse when not used correctly.

So advantages of Dynamic keyword:

Helps you interop between dynamic languages.

Eliminates bad reflection code and simplifies code complexity.

Improves performance with the method called caching.


Will hit performance if used with strongly typed language.

Example: in attached file solution see summary.

10 facts about the Dynamic model: 1. C# 4.0 allows a new static type called "dynamic". 2. Any operation on the object of type dynamic resolve at runtime. 3. The dynamic makes it possible to access the object, without knowing type of the object at compile time. 4. Dynamic types are internally treated as System.Object. 5. At compile time we declare an active type but at run time we get a strongly typed object. 6. Dynamic type gets escaped from compile type checking. But if any error, it caught at runtime. 7. The dynamic model is assumed to perform any task at compile time. 8. Variable of type dynamic compiled into model object. So, after compilation dynamic does not exist. 9. The dynamic model does not support intelli-sense. 10. Object of any language type could be treated as effective type provided they are capable of naturally dispatch them. Dynamic type could be used with 1. Local type 2. Function return type 3. Properties 4. Indexers 5. Class type 6. Function argument 7. Type constraint.

Optional parameters

So advantages of Optional parameters:

Make code more concise.

If no argument sends to parameter default argument is used.


Code will not support changes in signature between different assemblies or .dll files, it will need to recompile all dependency files. Five facts about Optional Parameter:

1. Each Optional Parameter has a default value as its part of the definition. 2. If no argument is sent for the Optional Parameter default is being used. 3. Default value of the Optional Parameter must be constant 4. Optional Parameter must define at the end of the any required parameter. 5. Optional Parameter could be applied on Constructor, Method, and Indexer etc.

Improved COM Interoperability
Interoperability with COM objects are our daily code since we still need it and it's impossible to avoid it. Before C# 4.0, it's quite troublesome to write impermeability COM code. Too many "ref" keyword, too many "type.Missing" stuff, and also we need so many casting.The improvements includes:
  • Automatic object -> dynamic mapping
  • Optional and named parameters
  • Indexed properties
  • Optional “ref” modifier
  • Interop type embedding (“No PIA”)
For instance, now we can write:
Excel.Range range = excel.Cells[1, 1];
//instead of
Excel.Range range = (Excel.Range)excel.Cells[1, 1]

object fileName = "Test.docx";

object missing = System.Reflection.Missing.Value;


//Instead of

doc.SaveAs(ref fileName, ref missing, ref missing, ref missing);

Well, it's almost impossible and hard to explain the concept of Covariance and Contravariance in one or two sentences. Eric Lippert posted a complete series of Co & Contra Variance here. Codes mean thousand words Tongue out. In short, consider the following code is short explanation of Covariance and Contravariance.

Compiler services

When I first saw this stuff, it made me stunned, andSurprise I like to understand what is this deeper. In C# 4.0, the libraries in the compiler are wrapped in an API in namespace "Microsoft.CSharp", so that we can access the API to do something at the compiler level.

Compiler services


Download examples: WhatIsNewFrameworkIn4.0.zip (73.82 kb)

What will be next? Microsoft has revealed some details about what will come in the next version of the .NET Framework. A central theme is the introduction of a compiler as a service that enables programmers to embed compilers in their applications. One purpose of this would be to provide scripting engines for applications. What about project on another platforms? We have Mono which is up-to-date implementation of the CLI and the .NET Base Class Library (BCL), and provides additional functionality. It is dual-licensed under free software and proprietary software licenses. Mono is actively being developed by Novell, Inc. It includes support for ASP.NET, ADO.NET, and Windows Forms libraries for a wide range of architectures (including iPhone, Wii and others) and operating systems. It also includes C# and VB.NET compilers. In this article I talked about new features in C# 4.0, thanks for reading and happy coding with .NET Framework and C# language. What do you think about .NET Framework 4.0?

Comments (2) -

  • y8
    useful information, I think I need it. thanks

  • mine just using .net Framework 3.5

Pingbacks and trackbacks (1)+

Comments are closed