Thursday, May 27, 2010

What's New in the .NET Framework 4

What's New in the .NET Framework 4

This topic contains information about key features and improvements in the .NET Framework version 4. This topic does not provide comprehensive information about all new features and is subject to change.

The .NET Framework 4 introduces an improved security model. For more information, see Security Changes in the .NET Framework 4.

Other new features and improvements in the .NET Framework 4 are described in the following sections:

Application Compatibility and Deployment

The .NET Framework 4 is highly compatible with applications that are built with earlier .NET Framework versions, except for some changes that were made to improve security, standards compliance, correctness, reliability, and performance.

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 older 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 Element in an application configuration file.

If your application or component does not work after .NET Framework 4 is installed, please submit a bug on the Microsoft Connect Web site. You can test compatibility as described in the .NET Framework 4 Application Compatibility topic and learn about new features by using the Visual Studio 2010 and .NET Framework 4 Walkthroughs. For additional information and known migration issues, visit the .NET Framework Compatibility blog.

The following sections describe deployment improvements.

Client Profile

The .NET Framework 4 Client Profile supports more platforms than in previous versions and provides a fast deployment experience for your applications. Several new project templates now target the Client Profile by default. For more information, see .NET Framework Client Profile.

In-Process Side-by-Side Execution

This feature enables an application to load and start multiple versions of the .NET Framework in the same process. For example, you can run applications that load add-ins (or components) that are based on the .NET Framework 2.0 SP1 and add-ins that are based on the .NET Framework 4 in the same process. Older components continue to use the older .NET Framework version, and new components use the new .NET Framework version. For more information, see In-Process Side-by-Side Execution.

Back to top

Core New Features and Improvements

The following sections describe new features and improvements provided by the common language runtime and the base class libraries.

Diagnostics and Performance

Earlier versions of the .NET Framework provided no way to determine whether a particular application domain was affecting other application domains, because the operating system APIs and tools, such as the Windows Task Manager, were precise only to the process level. Starting with the .NET Framework 4, you can get processor usage and memory usage estimates per application domain.

You can monitor CPU and memory usage of individual application domains. Application domain resource monitoring is available through the managed and native hosting APIs and event tracing for Windows (ETW). When this feature has been enabled, it collects statistics on all application domains in the process for the life of the process. See the new AppDomain.MonitoringIsEnabled property.

You can now access the ETW events for diagnostic purposes to improve performance. For more information, see CLR ETW Events and Controlling .NET Framework Logging. Also see Performance Counters and In-Process Side-By-Side Applications.

The System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptionsAttribute attribute enables managed code to handle exceptions that indicate corrupted process state.

Garbage Collection

The .NET Framework 4 provides background garbage collection. This feature replaces concurrent garbage collection in previous versions and provides better performance. For more information, see Fundamentals of Garbage Collection.

Code Contracts

Code contracts let you specify contractual information that is not represented by a method's or type's signature alone. The new System.Diagnostics.Contractsnamespace contains classes that provide a language-neutral way to express coding assumptions in the form of preconditions, postconditions, and object invariants. The contracts improve testing with run-time checking, enable static contract verification, and support documentation generation. For more information, see Code Contracts.

Design-Time-Only Interop Assemblies

You no longer have to ship primary interop assemblies (PIAs) to deploy applications that interoperate with COM objects. In the .NET Framework 4, compilers can embed type information from interop assemblies, selecting only the types that an application (for example, an add-in) actually uses. Type safety is ensured by the common language runtime. See Using COM Types in Managed Code and Walkthrough: Embedding Type Information from Microsoft Office Assemblies (C# and Visual Basic).

Dynamic Language Runtime

The dynamic language runtime (DLR) is a new runtime environment that adds a set of services for dynamic languages to the CLR. The DLR makes it easier to develop dynamic languages to run on the .NET Framework and to add dynamic features to statically typed languages. To support the DLR, the new System.Dynamicnamespace is added to the .NET Framework.

The expression trees are extended with new types that represent control flow, for example, System.Linq.Expressions.LoopExpression andSystem.Linq.Expressions.TryExpression. These new types are used by the dynamic language runtime (DLR) and not used by LINQ.

In addition, several new classes that support the .NET Framework infrastructure are added to the System.Runtime.CompilerServices namespace. For more information, see Dynamic Language Runtime Overview.

Covariance and Contravariance

Several generic interfaces and delegates now support covariance and contravariance. For more information, see Covariance and Contravariance in Generics.

BigInteger and Complex Numbers

The new System.Numerics.BigInteger structure is an arbitrary-precision integer data type that supports all the standard integer operations, including bit manipulation. It can be used from any .NET Framework language. In addition, some of the new .NET Framework languages (such as F# and IronPython) have built-in support for this structure.

The new System.Numerics.Complex structure represents a complex number that supports arithmetic and trigonometric operations with complex numbers.

Tuples

The .NET Framework 4 provides the System.Tuple class for creating tuple objects that contain structured data. It also provides generic tuple classes to support tuples that have from one to eight components (that is, singletons through octuples). To support tuple objects that have nine or more components, there is a generic tuple class with seven type parameters and an eighth parameter of any tuple type.

File System Enumeration Improvements

New file enumeration methods improve the performance of applications that access large file directories or that iterate through the lines in large files. For more information, see How to: Enumerate Directories and Files.

Memory-Mapped Files

The .NET Framework now supports memory-mapped files. You can use memory-mapped files to edit very large files and to create shared memory for interprocess communication.

64-Bit Operating Systems and Processes

You can identify 64-bit operating systems and processes with the Environment.Is64BitOperatingSystem and Environment.Is64BitProcess properties.

You can specify a 32-bit or 64-bit view of the registry with the Microsoft.Win32.RegistryView enumeration when you open base keys.

Other New Features

The following list describes additional new capabilities, improvements, and conveniences. Several of these are based on customer suggestions.

Back to top

Managed Extensibility Framework

The Managed Extensibility Framework (MEF) is a new library in the .NET Framework 4 that helps you build extensible and composable applications. MEF enables you to specify points where an application can be extended, to expose services to offer to other extensible applications and to create parts for consumption by extensible applications. It also enables easy discoverability of available parts based on metadata, without the need to load the assemblies for the parts. For more information, see Managed Extensibility Framework. For a list of the MEF types, see the System.ComponentModel.Composition namespace.

Back to top

Parallel Computing

The .NET Framework 4 introduces a new programming model for writing multithreaded and asynchronous code that greatly simplifies the work of application and library developers. The new model enables developers to write efficient, fine-grained, and scalable parallel code in a natural idiom without having to work directly with threads or the thread pool. The new System.Threading.Tasks namespace and other related types support this new model. Parallel LINQ (PLINQ), which is a parallel implementation of LINQ to Objects, enables similar functionality through declarative syntax. For more information, see Parallel Programming in the .NET Framework.

Back to top

Networking

Networking improvements include the following:

Back to top

Web

ASP.NET version 4 introduces new features in the following areas:

  • Core services, including a new API that lets you extend caching, support for compression for session-state data, and a new application preload manager (autostart feature).

  • 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.

  • Web Forms controls, including a new Chart control.

  • MVC, including new helper methods for views, support for partitioned MVC applications, and asynchronous controllers.

  • Dynamic Data, including support for existing Web applications, support for many-to-many relationships and inheritance, new field templates and attributes, and enhanced data filtering.

  • Microsoft Ajax, including additional support for client-based Ajax applications in the Microsoft Ajax Library.

  • Visual Web Developer, including improved IntelliSense for JScript, new auto-complete snippets for HTML and ASP.NET markup, and enhanced CSS compatibility.

  • Deployment, including new tools for automating typical deployment tasks.

  • Multi-targeting, including better filtering for features that are not available in the target version of the .NET Framework.

For more information about these features, see What's New in ASP.NET 4 and Visual Web Developer.

Back to top

Client

Windows Presentation Foundation

In the .NET Framework 4, Windows Presentation Foundation (WPF) contains changes and improvements in many areas, including controls, graphics, and XAML. For more information, see What's New in WPF Version 4.

Back to top

Data

ADO.NET

ADO.NET provides new features for the Entity Framework, including persistence-ignorant objects, functions in LINQ queries, and customized object layer code generation. For more information, see What's New in ADO.NET.

Dynamic Data

For ASP.NET 4, Dynamic Data has been enhanced to give you even more power for quickly building data-driven Web sites. This includes the following:

  • Automatic validation that is based on constraints that are defined in the data model.

  • 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.

For more information, see What's New in ASP.NET 4 and Visual Web Developer.

WCF Data Services

ADO.NET Data Service has been renamed to WCF Data Services, and has the following new features

  • Data binding.

  • Counting entities in an entity set.

  • Server-driven paging.

  • Query projections.

  • Custom data service providers.

  • Streaming of binary resources.

For more information, see What's New in WCF Data Services.

Back to top

Windows Communication Foundation

Windows Communication Foundation (WCF) provides the following improvements:

  • Configuration-based Activation: Removes the requirement for having an .svc file.

  • System.Web.Routing Integration: Allows you to have more control over your service's URL (extensionless URLs).

  • Multiple IIS Site Bindings Support: Allows you to have multiple base addresses with the same protocol on the same Web site.

  • Routing Service: Allows you to route messages based on content.

  • Support for WS-Discovery: Allows you to create and search for discoverable services.

  • Standard Endpoints: Predefined endpoints that allow you to specify only certain properties.

  • Workflow Services: Integrates WCF and WF by providing activities to send and receive messages, the ability to correlate messages based on content, and a workflow service host.

  • WCF REST features:

    • Web HTTP Caching: Allows caching of Web HTTP service responses.

    • Web HTTP Formats Support: Allows you to dynamically determine the best format for a service operation to respond in.

    • Web HTTP Services Help Page: Provides an automatic help page for Web HTTP services, similar to the WCF service help page.

    • Web HTTP Error Handling: Allows Web HTTP Services to return error information in the same format as the operation.

    • Web HTTP Cross-Domain JavaScript Support: Allows use of JSONP.

  • Simplified Configuration: Reduces the amount of configuration a service requires

For more information, see What's New in Windows Communication Foundation.

Back to top

Windows Workflow Foundation

Windows Workflow Foundation provides improvements in the following areas:

  • Improved Workflow Activity Model: The Activity class provides the base abstraction of workflow behavior.

  • Rich Composite Activity Options: Workflows benefit from new flow-control activities that model traditional flow-control structures, such as Flowchart, TryCatch, and Switch.

  • Expanded Built-In Activity Library: New features of the activity library include new flow-control activities, activities for manipulating member data, and activities for controlling transactions.

  • Explicit Activity Data Model: New options for storing or moving data include variable and directional arguments.

  • Enhanced Hosting, Persistence, and Tracking Options: Hosting enhancements include more options for running workflows, explicit persistence using the Persist activity, persisting without unloading, preventing persistence using no-persist zones, using ambient transactions from the host, recording tracking information to the event log, and resuming pending workflows using Bookmark.

  • Easier ability to extend the WF designer: The new WF Designer is built on Windows Presentation Foundation (WPF) and provides an easier model to use when rehosting the WF Designer outside of Visual Studio.

For more information, see What's New in Windows Workflow Foundation.

Back to top

What's New in Visual Basic 2010


Visual Studio 2010 - Visual Basic
What's New in Visual Basic 2010
This page lists the new and enhanced features available in Visual Basic 2010. Click the links in the following sections to read more about a feature.
Visual Basic Compiler and Language


Auto-Implemented Properties

Auto-implemented properties provide a shortened syntax that enables you to quickly specify a property of a class without having to write code to Get and Set the property. For more information, see Auto-Implemented Properties (Visual Basic).

Collection Initializers

Collection initializers provide a shortened syntax that enables you to create a collection and populate it with an initial set of values. Collection initializers are useful when you are creating a collection from a set of known values, for example, a list of menu options or categories. For more information, see Collection Initializers Overview (Visual Basic).

Implicit Line Continuation

In many cases, implicit line continuation enables you to continue a statement on the next consecutive line without using the underscore character (_). For a list of all the cases in which you can omit an underscore character, see Statements in Visual Basic.

Multiline Lambda Expressions and Subroutines

Lambda expression support has been expanded to support subroutines in addition to multiline lambda functions and subroutines. For more information, seeLambda Expressions.

New Command-Line Option for Specifying a Language Version

The /langversion command-line option causes the compiler to accept only syntax that is valid in the specified version of Visual Basic.

Type Equivalence Support

You can now deploy an application that has embedded type information instead of type information that is imported from a Primary Interop Assembly (PIA). With embedded type information, your application can use types in a runtime without requiring a reference to the runtime assembly. If various versions of the runtime assembly are published, the application that contains the embedded type information can work with the various versions without having to be recompiled. For more information, see /link (Visual Basic). For an example, see Walkthrough: Embedding Types from Managed Assemblies (C# and Visual Basic).

Dynamic Support

Visual Basic binds to objects from dynamic languages such as IronPython and IronRuby. For more information, see Working with Dynamic Objects (Visual Basic) andWalkthrough: Creating and Using Dynamic Objects (C# and Visual Basic).

Covariance and Contravariance

Covariance enables you to use a more derived type than that specified by the generic parameter, whereas contravariance enables you to use a less derived type. This allows for implicit conversion of classes that implement variant interfaces and provides more flexibility for matching method signatures with variant delegate types. You can create variant interfaces and delegates by using the new In and Out language keywords. The .NET Framework also introduces variance support for several existing generic interfaces and delegates, including the IEnumerable(Of T) interface and the Func(Of TResult) and Action(Of T) delegates. For more information, see Covariance and Contravariance (C# and Visual Basic).
Integrated Development Environment


The following sections describe enhancements to the Visual Studio integrated development environment (IDE).

Navigate To

You can use the Navigate To feature to search for a symbol or file in source code. You can search for keywords that are contained in a symbol by using Camel casing and underscore characters to divide the symbol into keywords.
For more information, see How to: Search for Objects, Definitions, and References (Symbols).

Highlighting References

When you click a symbol in source code, all instances of that symbol are highlighted in the document.
For many control structures, when you click a keyword, all of the keywords in the structure are highlighted. For instance, when you click If in an If...Then...Elseconstruction, all instances of If, Then, ElseIf, Else, and End If in the construction are highlighted.
To move to the next or previous highlighted symbol, you can use CTRL+SHIFT+DOWN ARROW or CTRL+SHIFT+UP ARROW. For more information, see How to: Use Reference Highlighting.

Generate From Usage

The Generate From Usage feature enables you to use classes and members before you define them. You can generate a stub for any class, constructor, method, property, field, or enum that you want to use but have not yet defined. You can generate new types and members without leaving your current location in code. This minimizes interruption to your workflow.
Generate From Usage supports programming styles such as test-first development. For more information, see Generate From Usage.

IntelliSense Suggestion Mode

IntelliSense now provides two alternatives for IntelliSense statement completion: completion mode and suggestion mode. Suggestion mode is used when classes and members are used before they are defined. For more information, see List Members.
Sample Applications


Visual Basic includes new sample applications that demonstrate the following features: auto-implemented properties, implicit line continuation, collection initializers, covariance and contravariance, and multiline lambda expressions and subroutines. For information about Visual Basic language samples and how to access them, see Visual Basic Language Samples.

What's New in Visual C# 2010

What's New in Visual C# 2010

This page lists the new and enhanced features available in Visual C# 2010. The new features work together to improve Microsoft Office programmability, increase your ability to explore code, provide support for test-driven development, and more. For more information, see Visual Studio 2010 Product Highlights.

Click the links in the following sections to read more about a feature.

C# 4.0 Language and Compiler

Dynamic Support

Visual C# 2010 provides support for late binding to dynamic types by introducing a new type, dynamic. This addition enables many new scenarios, including simplified access to COM APIs such as the Office Automation APIs, to dynamic APIs such as IronPython libraries, and to the HTML Document Object Model (DOM). For more information, see Using Type dynamic (C# Programming Guide) and dynamic (C# Reference).

Office Programmability

Access to COM interfaces, including the Office Automation APIs, is greatly enhanced by the addition of named and optional arguments, the dynamic type, indexed properties and optional ref modifiers.

For more information, see Named and Optional Arguments (C# Programming Guide), Using Type dynamic (C# Programming Guide), How to: Use Indexed Properties in COM Interop Programming (C# Programming Guide), and How to: Access Office Interop Objects by Using Visual C# 2010 Features (C# Programming Guide).

Type Equivalence Support

You can now deploy an application that has embedded type information instead of type information that is imported from a Primary Interop Assembly (PIA). With embedded type information, your application can use types in a runtime without requiring a reference to the runtime assembly. If various versions of the runtime assembly are published, the application that contains the embedded type information can work with the various versions without having to be recompiled. For more information, see /link (C# Compiler Options). For an example, see Walkthrough: Embedding Types from Managed Assemblies (C# and Visual Basic).

Covariance and Contravariance

Covariance enables you to use a more derived type than that specified by the generic parameter, whereas contravariance enables you to use a less derived type. This allows for implicit conversion of classes that implement variant interfaces and provides more flexibility for matching method signatures with variant delegate types. Variant interfaces and delegates can be created by using the new in and out language keywords. The .NET Framework also introduces variance support for several existing generic interfaces and delegates, including the IEnumerable(Of T) interface and the Func(Of TResult) and Action(Of T) delegates. For more information, see Covariance and Contravariance (C# and Visual Basic).

New Command-Line Options

The /langversion command-line option causes the compiler to accept only syntax that is valid in the specified version of C#.

The /appconfig compiler option enables a C# application to specify the location of an assembly's application configuration file to the compiler.

Visual C# Integrated Development Environment

The following sections describe enhancements to the Visual Studio integrated development environment (IDE).

Call Hierarchy

Call Hierarchy enables you to navigate through your code by displaying the following:

  • All calls to and from a selected method, property, or constructor

  • All implementations of an interface member

  • All overrides of a virtual or abstract member

This enables you to better understand how code flows and to evaluate the effects of changes to code. For more information, see Call Hierarchy.

Navigate To

You can use the Navigate To feature to search for a symbol or file in source code. You can search for keywords that are contained in a symbol by using Camel casing and underscore characters to divide the symbol into keywords.

For more information, see How to: Search for Objects, Definitions, and References (Symbols).

Highlighting References

When you click a symbol in source code, all instances of that symbol are highlighted in the document. To move to the next or previous highlighted symbol, you can use CTRL+SHIFT+DOWN ARROW or CTRL+SHIFT+UP ARROW. For more information, see How to: Use Reference Highlighting.

Generate From Usage

The Generate From Usage feature enables you to use classes and members before you define them. Without leaving your current location in code, you can generate a stub for a class, constructor, method, property, field, or enum that you want to use but have not yet defined. This minimizes interruption to your workflow.

Generate From Usage supports programming styles such as test-first development. For more information, see Generate From Usage and Walkthrough: Test-First Support with the Generate From Usage Feature.

IntelliSense Suggestion Mode

IntelliSense now provides two alternatives for IntelliSense statement completion: completion mode and suggestion mode. Suggestion mode is used when classes and members are used before they are defined. For more information, see List Members.

Live Semantic Errors

The Live Semantic Errors feature has been enhanced in Visual C# 2010. The use of wavy underlines to signal errors and warnings as you type has been extended to include constructs that are outside of method bodies, such as return types, parameter types, and default values in method declarations.

Sample Applications

Visual C# 2010 includes sample applications that demonstrate the use of new C# features to simplify Office programming, provide access to IronPython libraries, create dynamic objects, develop and use covariant and contravariant generic delegates, and more. For information about Visual C# language samples and how to access them, see Visual C# Sample Applications.

Saturday, May 2, 2009

Sending Email usin asp


Sending email in Active
Server Pages isn’t at complex as it seems. All you need is an ASP
Page that contains your code, a host that supports ASP and CDONTS
(Collaborative Data Objects for Windows NT Server), and a basic knowledge of
Active Server Pages.
CDONTS provides you with objects and classes that enable
you to send email from an ASP page. CDONTS only works on Windows NT/2000 Operating Systems, but it has powerful functions, allowing you to:
* attach files while sending email,
* send email in HTML Format,

use the Carbon Copy(CC) and Blind Carbon
Copy(BCC) functions as in any email client,

set email priority

..and that’s just the beginning! Again, the process is
not as complicated as it seems.


Create CDONTS


First of all, we must create an instance of the CDONTS on
the server using this code:

<%Set Mail=Server.CreateObject(CDONTS.NewMail”)
%>
In the above code, you can replace Mail with any other variable, but you must be sure to use
that variable constantly. Now that we’ve created an instance of CDONTS on the
server, we need to input the required values.
Input Your Values
The first input should be the Recipient to whom we’ll
send the email. To add the Recipient address, use:
<%Mail.to=” me@mydomain.com”
%>
Mail.to consists of the same variable that we used to name the
instance of our
CDONTS.NewMail The to after the . tells the object
the address to which the email should be sent. So now our code looks like this:
<%
Set Mail=Server.CreateObject(“CDONTS.NewMail”)
Mail.to=” me@mydomain.com”
%>
Now we need to tell the object the email address of the
Sender, using:

<%Mail.From=” testing-my@SP-Script.com”
%>
The From field after Mail. indicates the email address of
the Sender. The email address should always appear in quotes. With this
addition, our code becomes:
<%Set Mail=Server.CreateObject(CDONTS.NewMail”)
Mail.To=”me@mydomain.com
Mail.From=”testing-my@SP-Script.com
%>
By now you’re clear on the concept of using the main
classes, so let’s look at how to add the Subject line to the email. If you
haven’t already guessed, this is how to do it:
<%Mail.Subject=”Just testing my script”
%>
Now the code is:
<%Set Mail=Server.CreateObject(CDONTS.NewMail”)
Mail.To=”me@mydomain.com
Mail.From=”testing-my@SP-Script.com
Mail.Subject=”Just testing my script”
%>
All that's left now is the content of the email, which we
add like this:
<%Mail.Body=”Hey! I am sending this email through an ASP Page, and
guess what? I haven’t learnt much yet, but
know that ASP is very

powerful.”
%>
The Body class represents the content of the email
we’re sending. It can contain any sort of text, but it doesn’t recognize HTML tags -- it would
simply send these as normal text.

So to sum up, our code looks like this:

<%
Set Mail=Server.CreateObject(CDONTS.NewMail”)
Mail.To=”me@mydomain.com
Mail.From=”testing-my@SP-Script.com
Mail.Subject=”Just testing my script”
Mail.Body=”Hey! I am sending this email through an ASP
Page and

guess what? I haven’t learnt much yet, but
know that ASP is very

powerful.”
%>

OK. Now it’s time to send the email, using:
<%Mail.Send
%>
And that should do it! Our code is neat and should
successfully send the email. Let's take a last look at the complete code:


<%Set Mail=Server.CreateObject(CDONTS.NewMail”)
Mail.To=”me@mydomain.com
Mail.From=”testing-my@SP-Script.com
Mail.Subject=”Just testing my script”
Mail.Body=”Hey! I am sending this email through an ASP Page and
guess what? I haven’t learnt much yet, but
know that ASP is very

powerful.”
Mail.Send
Set Mail=nothing
%>
The last line: Set
Mail=nothing
releases
the instance of the object -- and hence some resources -- from the server. This
will make your Server Administrator happy!

You can now copy and paste the above code into your favorite
editor, save it as SendingEmail.asp (remember the file extension), and upload
it to your Website. Remember to replace the Recipient's as well as the Sender's
email addresses with your own. Now you can visit the page you’ve uploaded, and
read the email you sent through the ASP page.
Obtaining Addresses
You can also use fields that are requested through a form
or querystring to obtain recipients’ email addresses. If you use form or querystring for the Recipient
field, then the code for the
.To would look like
this:
<%‘ In case of requesting recipient’s address
from a form

Mail.to=request.form(“txteMail”)
txteMail is just
a variable, you can change it as per your form

%>
<%
‘In case of QuerystringMail.To=Request.QueryString(“email”)
eMail is just a
variable, again you can change it as per your page

%>
Extra Help?


Now we’ve explored how to send email
through an ASP page – and found that it’s extremely simple. If you have any
problems or questions, or you find ASP email confusing, try posting your
problems at SitePoint
Forums
. Our loyal members will be pleased to help you out!


A Parting Project:

To practice what you've learnt, create a page which asks a user for their email
address, and sends them a test email. It won’t be difficult if you've
understood this tutorial!