Tuesday, September 28, 2010

LINQ – Language Integrated Query 101

This is a collection of information related to LINQ.  The primary purpose is to provide a reference for getting started with LINQ.

LINQ is a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities.

Language-Integrated Query (LINQ) is an innovation introduced in Visual Studio 2008 and .NET Framework version 3.5 that bridges the gap between the world of objects and the world of data.

Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support. Furthermore, you have to learn a different query language for each type of data source: SQL databases, XML documents, various Web services, and so on. LINQ makes a query a first-class language construct in C# and Visual Basic. You write queries against strongly typed collections of objects by using language keywords and familiar operators. The following illustration shows a partially-completed LINQ query against a SQL Server database in C# with full type checking and IntelliSense support.

LINQ query with Intellisense

In Visual Studio you can write LINQ queries in Visual Basic or C# with SQL Server databases, XML documents, ADO.NET Datasets, and any collection of objects that supports IEnumerable or the generic IEnumerable(Of T) interface. LINQ support for the ADO.NET Entity Framework is also planned, and LINQ providers are being written by third parties for many Web services and other database implementations.

You can use LINQ queries in new projects, or alongside non-LINQ queries in existing projects. The only requirement is that the project target .NET Framework 3.5 or later.

A query is an expression that retrieves data from a data source. Queries are expressed in a dedicated query language. Over time, different languages have been developed for different types of data sources, for example, SQL for relational databases and XQuery for XML. This makes it necessary for the application developer to learn a new query language for each type of data source or data format that is supported.

Language-Integrated Query (LINQ) simplifies the situation by offering a consistent model for working with data across various kinds of data sources and formats. In a LINQ query, you are always working with objects. You use the same basic coding patterns to query and transform data in XML documents, SQL databases, ADO.NET datasets and entities, .NET Framework collections, and any other source or format for which a LINQ provider is available. This document describes the three phases of the creation and use of basic LINQ queries.

Three Stages of a Query Operation

LINQ query operations consist of three actions:

  1. Obtain the data source or sources.

  2. Create the query.

  3. Execute the query.

In LINQ, the execution of a query is distinct from the creation of the query. You do not retrieve any data just by creating a query. This point is discussed in more detail later in this topic.

The following example illustrates the three parts of a query operation. The example uses an array of integers as a convenient data source for demonstration purposes. However, the same concepts also apply to other data sources.

' Data source.
Dim numbers() As Integer = {0, 1, 2, 3, 4, 5, 6}

' Query creation.
Dim evensQuery = From num In numbers
                 Where num Mod 2 = 0
                 Select num

' Query execution.
For Each number In evensQuery
    Console.Write(number & " ")


0 2 4 6

The Data Source

Because the data source in the previous example is an array, it implicitly supports the generic IEnumerable(Of T) interface. It is this fact that enables you to use an array as a data source for a LINQ query. Types that support IEnumerable(Of T), or a derived interface such as the generic IQueryable(Of T), are called queryable types.

As an implicitly queryable type, the array requires no modification or special treatment to serve as a LINQ data source. The same is true for any collection type that supports IEnumerable(Of T), including the generic List(Of T), Dictionary(Of TKey, TValue), and other classes in the .NET Framework class library.

If the source data does not already implement IEnumerable(Of T), a LINQ provider is needed to implement the functionality of the standard query operators for that data source. For example, LINQ to XML handles the work of loading an XML document into a queryable XElement type, as shown in the following example. For more information about standard query operators, see Standard Query Operators Overview.

' Create a data source from an XML document.
Dim contacts = XElement.Load("c:\myContactList.xml")

With LINQ to SQL, you first create an object-relational mapping at design time, either manually or by using the Object Relational Designer (O/R Designer). You write your queries against the objects, and at run-time LINQ to SQL handles the communication with the database. In the following example, customers represents a specific table in the database, and Table(Of TEntity) supports generic IQueryable(Of T).

' Create a data source from a SQL table.
Dim db As New DataContext("C:\Northwind\Northwnd.mdf")
Dim customers As Table(Of Customer) = db.GetTable(Of Customer)

For more information about how to create specific types of data sources, see the documentation for the various LINQ providers. (For a list of these providers, see Language-Integrated Query (LINQ).) The basic rule is simple: a LINQ data source is any object that supports the generic IEnumerable(Of T) interface, or an interface that inherits from it.


Types such as ArrayList that support the non-generic IEnumerable interface can also be used as LINQ data sources. For an example that uses an ArrayList, see How to: Query an ArrayList with LINQ.

The Query

In the query, you specify what information you want to retrieve from the data source or sources. You also have the option of specifying how that information should be sorted, grouped, or structured before it is returned. To enable query creation, Visual Basic has incorporated new query syntax into the language.

When it is executed, the query in the following example returns all the even numbers from an integer array, numbers.

' Data source.
Dim numbers() As Integer = {0, 1, 2, 3, 4, 5, 6}

' Query creation.
Dim evensQuery = From num In numbers
                 Where num Mod 2 = 0
                 Select num

' Query execution.
For Each number In evensQuery
    Console.Write(number & " ")

The query expression contains three clauses: From, Where, and Select. The specific function and purpose of each query expression clause is discussed in Basic Query Operations (Visual Basic). For more information, see Queries (Visual Basic). Note that in LINQ, a query definition often is stored in a variable and executed later. The query variable, such as evensQuery in the previous example, must be a queryable type. The type of evensQuery is IEnumerable(Of Integer), assigned by the compiler using local type inference.

It is important to remember that the query variable itself takes no action and returns no data. It only stores the query definition. In the previous example, it is the For Each loop that executes the query.

Query Execution

Query execution is separate from query creation. Query creation defines the query, but execution is triggered by a different mechanism. A query can be executed as soon as it is defined (immediate execution), or the definition can be stored and the query can be executed later (deferred execution).

Deferred Execution

A typical LINQ query resembles the one in the previous example, in which evensQuery is defined. It creates the query but does not execute it immediately. Instead, the query definition is stored in the query variable evensQuery. You execute the query later, typically by using a For Each loop, which returns a sequence of values, or by applying a standard query operator, such as Count or Max. This process is referred to as deferred execution.

' Query execution that results in a sequence of values.
For Each number In evensQuery
    Console.Write(number & " ")

' Query execution that results in a single value.
Dim evens = evensQuery.Count()

For a sequence of values, you access the retrieved data by using the iteration variable in the For Each loop (number in the previous example). Because the query variable, evensQuery, holds the query definition rather than the query results, you can execute a query as often as you want by using the query variable more than one time. For example, you might have a database in your application that is being updated continually by a separate application. After you have created a query that retrieves data from that database, you can use a For Each loop to execute the query repeatedly, retrieving the most recent data every time.

The following example demonstrates how deferred execution works. After evensQuery2 is defined and executed with a For Each loop, as in the previous examples, some elements in the data source numbers are changed. Then a second For Each loop runs evensQuery2 again. The results are different the second time, because the For Each loop executes the query again, using the new values in numbers.

Dim numberArray() = {0, 1, 2, 3, 4, 5, 6}

Dim evensQuery2 = From num In numberArray
                  Where num Mod 2 = 0
                  Select num

Console.WriteLine("Evens in original array:")
For Each number In evensQuery2
    Console.Write("  " & number)

' Change a few array elements.
numberArray(1) = 10
numberArray(4) = 22
numberArray(6) = 8

' Run the same query again.
Console.WriteLine(vbCrLf & "Evens in changed array:")
For Each number In evensQuery2
    Console.Write("  " & number)


Evens in original array:

0 2 4 6

Evens in changed array:

0 10 2 22 8

Immediate Execution

In deferred execution of queries, the query definition is stored in a query variable for later execution. In immediate execution, the query is executed at the time of its definition. Execution is triggered when you apply a method that requires access to individual elements of the query result. Immediate execution often is forced by using one of the standard query operators that return single values. Examples are Count, Max, Average, and First. These standard query operators execute the query as soon as they are applied in order to calculate and return a singleton result. For more information about standard query operators that return single values, see Aggregation Operations, Element Operations, and Quantifier Operations.

The following query returns a count of the even numbers in an array of integers. The query definition is not saved, and numEvens is a simple Integer.

Dim numEvens = (From num In numbers
                Where num Mod 2 = 0
                Select num).Count()

You can achieve the same result by using the Aggregate method.

Dim numEvensAgg = Aggregate num In numbers
                  Where num Mod 2 = 0
                  Select num
                  Into Count()

You can also force execution of a query by calling the ToList or ToArray method on a query (immediate) or query variable (deferred), as shown in the following code.

' Immediate execution.
Dim evensList = (From num In numbers
                 Where num Mod 2 = 0
                 Select num).ToList()

' Deferred execution.
Dim evensQuery3 = From num In numbers
                  Where num Mod 2 = 0
                  Select num
' . . .
Dim evensArray = evensQuery.ToArray()

In the previous examples, evensQuery3 is a query variable, but evensList is a list and evensArray is an array.

Using ToList or ToArray to force immediate execution is especially useful in scenarios in which you want to execute the query immediately and cache the results in a single collection object. For more information about these methods, see Converting Data Types.

You can also cause a query to be executed by using an IEnumerable method such as the IEnumerable.GetEnumerator method.

The standard query operators are the methods that form the Language-Integrated Query (LINQ) pattern. Most of these methods operate on sequences, where a sequence is an object whose type implements the IEnumerable(Of T) interface or the IQueryable(Of T) interface. The standard query operators provide query capabilities including filtering, projection, aggregation, sorting and more.

There are two sets of LINQ standard query operators, one that operates on objects of type IEnumerable(Of T) and the other that operates on objects of type IQueryable(Of T). The methods that make up each set are static members of the Enumerable and Queryable classes, respectively. They are defined as extension methods of the type that they operate on. This means that they can be called by using either static method syntax or instance method syntax.

In addition, several standard query operator methods operate on types other than those based on IEnumerable(Of T) or IQueryable(Of T). The Enumerable type defines two such methods that both operate on objects of type IEnumerable. These methods, Cast(Of TResult)(IEnumerable) and OfType(Of TResult)(IEnumerable), let you enable a non-parameterized, or non-generic, collection to be queried in the LINQ pattern. They do this by creating a strongly-typed collection of objects. The Queryable class defines two similar methods, Cast(Of TResult)(IQueryable) and OfType(Of TResult)(IQueryable), that operate on objects of type Queryable.

The standard query operators differ in the timing of their execution, depending on whether they return a singleton value or a sequence of values. Those methods that return a singleton value (for example, Average and Sum) execute immediately. Methods that return a sequence defer the query execution and return an enumerable object.

In the case of the methods that operate on in-memory collections, that is, those methods that extend IEnumerable(Of T), the returned enumerable object captures the arguments that were passed to the method. When that object is enumerated, the logic of the query operator is employed and the query results are returned.

In contrast, methods that extend IQueryable(Of T) do not implement any querying behavior, but build an expression tree that represents the query to be performed. The query processing is handled by the source IQueryable(Of T) object.

Calls to query methods can be chained together in one query, which enables queries to become arbitrarily complex.

The following code example demonstrates how the standard query operators can be used to obtain information about a sequence.

Dim sentence = "the quick brown fox jumps over the lazy dog"
' Split the string into individual words to create a collection.
Dim words = sentence.Split(" "c)

Dim query = From word In words
            Group word.ToUpper() By word.Length Into gr = Group
            Order By Length _
            Select Length, GroupedWords = gr

Dim output As New System.Text.StringBuilder
For Each obj In query
    output.AppendLine(String.Format("Words of length {0}:", obj.Length))
    For Each word As String In obj.GroupedWords

'Display the output

' This code example produces the following output:
' Words of length 3:
' Words of length 4:
' Words of length 5:

Query Expression Syntax

Some of the more frequently used standard query operators have dedicated C# and Visual Basic language keyword syntax that enables them to be called as part of a query expression. For more information about standard query operators that have dedicated keywords and their corresponding syntaxes, see Query Expression Syntax for Standard Query Operators.

Extending the Standard Query Operators

You can augment the set of standard query operators by creating domain-specific methods that are appropriate for your target domain or technology. You can also replace the standard query operators with your own implementations that provide additional services such as remote evaluation, query translation, and optimization. See AsEnumerable(Of TSource) for an example.


Video on getting started with LINQ, ttp://

Video on writing LINQ,

Guy Burstein’s Blog on Like Operators,

Guy Burstein’s LINQ blog posts,

Microsoft LINQ Developer Center,

Microsoft LINQ sorting,

Microsoft LINQ filtering,

Microsoft LINQ set operations,

Microsoft LINQ quantifier operations,

Friday, September 24, 2010

Microsoft Visual Basic .Net CPT for Windows Phone Developer Tools Released!

Many of you have asked if Visual Basic can be used to write Windows Phone applications. 

As of today, the answer is "yes!"

Starting today, you can download Microsoft Visual Basic CTP for Windows Phone Developer Tools.  This is a great milestone as it enables our Visual Basic developers to be able to build applications for Windows Phone.

Applications built using the CTP run on both the emulator and the phone. To try the CTP, you'll need the final version of Windows Phone Developer Tools and Visual Studio 2010 Professional or higher. If you don't have Visual Studio 2010 Professional, you can install the free trial of Visual Studio Professional

The CTP includes Visual Studio 2010 project templates, item templates, designer support, emulator support, debugging, and IntelliSense for Visual Basic.  After installing the CTP, Visual Studio 2010 Professional and higher users will find Windows Phone project types for Visual Basic in the New Project Dialog, as you can see below.

Wednesday, September 08, 2010

Resource Refactoring Tool


Resource Refactoring Tool provides developers an easy way to extract hard coded strings from the code to resource files.

Features for Resource Refactoring Tool

  • Works with C#, VB.Net languages. Supports all project types that ships with Visual Studio 2005 including web sites and web application projects.
  • A preview window to show changes.
  • Finds other instances of the text being replaced in the project automatically.
  • Lists existing resources by their similarity level to the text being replaced.
  • Automatically replaces hard coded string with a reference to resource entry.

Quick Start to using Resource Refactoring Tool
  1. Run ResourceRefactor.msi to install. If you have any earlier version please uninstall those versions first and run Visual Studio at least once before installing the new version.
  2. Launch Visual Studio 2005
  3. Open either a VB.Net or C# project
  4. Right click on a hard coded string in a a code window and choose Refactor - Extract to resource. If you don't see the menu item and you had a previous version of Resource Refactoring Tool installed before, you may have to reset the addin by running Visual Studio from Visual Studio 2005 Command Prompt with the following arguments: devenv.exe /resetaddin Microsoft.VSPowerToys.ResourceRefactor.Connect. This should fix the missing menu items.
  5. RefactoringTool-Menu.png
  6. Choose the resource file you want to use and either choose an existing resource or create a new one. After closing the dialog window, string will automatically be replaced with the reference to resource you have chosen.

Contributing to Resource Refactoring Tool
We're looking for developers to join us in future releases. Check out the current work items at issue tracker.
Feel free to contribute by
  1. Reading Getting Started with Resource Refactoring Tool Development.
  2. Either creating new or finding existing bugs or feature requests you want to work on
  3. Leave a note in the comments that you're going to investigate this bug (until you have developer rights, you won't be able to assign bugs to yourself)
  4. Download the latest sources and create a bug fix
  5. Zip up your changes and post them as an attachment to the work item
  6. Fill out the Project_Assignment_Agreement.TIF form and follow the Assignment Agreement Instructions to send it to us.

Note that by posting your submission to the Issue Tracker, you agree to do so under the CodePlex TOU
Join the Community
There are numerous ways you can participate in the Resource Refactoring Tool community
  • Blog about Resource Refactoring Tool
  • Ask and answer questions regarding Resource Refactoring Tool on the discussions tab
  • Fix bugs or check in new features - see above section

Visual Studio 2010 Image Insertion

Image Insertion


This sample was created to show how easy it is to extend the Visual Studio 2010 editor.  The Image Insertion sample lets you insert images directly in line with your code to help you visualize aspects of your code.  The editor extension supports drag and drop from the solution explorer and automatically sizes images to the space available pushing aside the text to make sure everything is readable.

Image Insertion Microsoft Training Pivot view

Check out the msdev Pivot site at to experience a great new way to find the right courses for your needs! Pivot makes it easier to interact with massive amounts of data in ways that are powerful, informative and fun.

Windows Phone 7 in 7 Minutes! Free webcasts to get you started! is offering several good short video on windows 7 phone.

Microsoft Web Farm Framework

This is a great article on the new free product from Microsoft by Scott Guthrie.

Introducing the Microsoft Web Farm Framework

Last month we released a beta of the Microsoft Web Farm Framework. The Microsoft Web Farm Framework is a free product we are shipping that enables you to easily provision and mange a farm of web servers.  It enables you to automate the installation and configuration of platform components across the server farm, and enables you to automatically synchronize and deploy ASP.NET applications across them.  It also supports integration with load balancers - and enables you to automate updates across your servers so that your site/application is never down or unavailable to customers (it can automatically pull servers one-at-a-time out of the load balancer rotation, update them, and then inject them back into rotation).

The Microsoft Web Farm Framework is a 1 MB download, and can be installed on IIS 7 and above. It is available for free. You can download the first preview of this beta here: x86 / x64.

Why Is the Web Farm Framework Useful?

Running a web farm requires you to provision and manage multiple servers.  Running a web farm involves (among other things):

  1. Installing IIS, ASP.NET and all of the core platform components on the servers
  2. Installing and configuring custom IIS modules (UrlRewite, Media Services, etc)
  3. Configuring IIS Application Pools and Sites
  4. Setting up SSL certificates for things like HTTPs endpoints
  5. Copying and synchronizing the appropriate sites/applications/content across the various boxes
  6. Coordinating the various web servers with a HTTP load balancer to distribute load

Administrators and developers managing a web farm today often perform a lot of manual steps to do the above (which is error prone and dangerous), or write a lot of custom scripts to automate it (which is time consuming and hard).  Adding new servers or making configuring or application changes can often be painful and time-consuming.

The Microsoft Web Farm Framework makes this process much easier, and enables you to manage web farms in a completely automated way. Best of all, it is really easy to setup and use.

Using Web Farm Framework to Provision and Scale a Web Farm

The Microsoft Web Farm Framework enables you to easily define a “Server Farm” that you can add any number of servers into.  Servers participating in the “Server Farm” will then be automatically updated, provisioned and managed by the Web Farm Framework. 

What this means is that you can install IIS (including modules like UrlRewrite, Media Services, etc), ASP.NET, and custom SSL certificates once on a primary server – and then the Web Farm Framework will automatically replicate and provision the exact same configuration across all of the other web servers in the farm (no manual or additional steps required). 

You can then create and configure an IIS Application Pool and a new Site and Application once on a primary server – and the Web Farm Framework will automatically replicate and provision the settings to all of the other web servers in the farm.  You can then copy/deploy an ASP.NET application once on the primary server – and the Web Farm Framework will automatically replicate and provision the changes to all of the web servers in the farm (no manual or additional steps required).

The Web Farm Framework eliminates the need to manually install/manage things across a cluster of machines.  It handles all of the provisioning and deployment for you in a completely automated way.

Load Balancer Integration

In addition to making it easy to provision/deploy servers and applications, the Web Farm Framework also includes load balancer integration. Specifically, the Web Farm Framework can integrate with an HTTP load balancer so that as web servers in the farm are updated with changes, they can be automatically pulled out of a load balancer rotation, updated, and then added back in.  The Web Farm Framework can also optionally update the machines one at a time – so that you always have servers available to handle heavily load.  This enables you to keep your site always available during updates – without you having to write any manual scripts to control or manage the update roll-out.

The current beta of the Web Farm Framework includes built-in support for the IIS Application Request Routing (ARR) service (which supports automatic load balancing of HTTP requests across multiple machines in a web-farm).  The Web Farm Framework makes it really easy to integrate your web farm of servers with ARR for load-balancing, and includes the support to automatically pull a server out of rotation as it is being updated, and then have it added back into rotation once the update is done.

The final Web Farm Framework release will enable extensibility with other load-balancing technologies as well – enabling the same ability to automatically pull/inject servers from a load balancing rotation as they are updated.

Scenario Walkthrough: Setting up and Provisioning a Web Farm

Let’s walkthrough a simple scenario where we want to setup and manage a server farm made up of two web servers.  We’ll call these two web-servers the “DemoPrimary” and “DemoSeconday” servers.  We’ll use a third “DemoController” machine to coordinate and manage the web farm.  DemoController doesn’t technically need to be a separate machine – but makes it easier to understand the various roles in the walkthrough.


Installing the Web Farm Framework

We’ll begin by installing the current beta of the Microsoft Web Farm Framework using the Microsoft Web Platform Installer on our “DemoController” machine. It works with any machine that has IIS 7 (and above) installed.

Creating and Provisioning a Web Farm

Once the Microsoft Web Farm Framework is installed, you’ll find a new “Server Farm” node listed within the left-hand tree view of the IIS Admin Tool on the “DemoController” machine.  If you right-click on this “Server Farm” node you’ll see an option to “Create Server Farm…”


Selecting this option will bring up a “Create Server Farm” dialog – and allow us to configure and setup a farm of machines that we want to manage together.

We’ll name the new server farm we want to create “DemoFarm”, and indicate that we want to automatically provision all of the servers in the farm (by checking the “Provision Server Farm” option in the dialog).  We’ll also indicate that we want to make it available for load-balancing with the IIS Application Request Routing (ARR) load-balancer:


When we click the “Next” button the wizard will bring up an “Add Servers” dialog that allows us to specify the servers we want to have in the web farm. We can add any number of servers at the time of first setup.  We can also come back and add more servers to the server farm later.  When you add more servers to the farm later, the Web Farm Framework will automatically provision and update them to have the latest changes (allowing us to easily add additional capacity at any time).

For this walkthrough we’ll add our two servers – “DemoPrimary” and “DemoSeconday” to our server farm.  We’ll start by adding the “DemoPrimary” machine.  We’ll select the “Primary Server” checkbox in the dialog – which will indicate that its role is to act as the primary server that the other servers in the farm will replicate:


Once we add the “DemoPrimary” server we’ll also add the “DemoSecondary” server to the farm.  


When we click the “Finish” button the Web Farm Framework will connect to the servers we’ve added to the farm and automatically provision the appropriate management software on them for us (no need for us to install anything manually – the web farm framework will automatically install its management service on the target machines).  Clicking the “servers” tab in the “Server Farm” node in the IIS Admin tool always provides an up-to-date view of the provisioning and deployment operations happening across all the farm (you can also filter it by individual server if you want):


At this point we are completely done configuring our web farm.  We now have a working, automated, web farm enabled. 

We have setup our web farm for automated provisioning and synchronization/replication.  If we were to create sites or application pools on the “DemoPrimary” web server, or install or update applications on it, they would be automatically replicated/synchronized on the “DemoSeconday” server.  This is also true for any web platform components we install. We do not need to manually install or configure anything on any additional secondary servers we add to the farm. The Web Farm Framework will automate keeping them synchronized with our Primary Server – and enable us to manage the entire farm of servers as a group.

Managing a Web Farm

Clicking on the “DemoFarm” sub-node within the IIS Admin Tool enables us to manage, track and configure our server farm:


The view above combines the settings of both the Web Farm Framework, as well as the Application Request Routing capability of IIS (which adds load-balancing and cache management support). 

You can click on the “Servers” sub-node of “DemoFarm” to see how the servers within the web farm are doing, if they are currently performing any deployment/provisioning operations, and if any errors have occurred on them.  If any provisioning/deployment errors have occurred anywhere in the farm, you can drill down to detailed tracing to see what they were.

Platform Provisioning using the Web Farm Framework

The Web Farm Framework enables you to easily add more platform components to your server-farm machines at anytime by using the “Platform Provisioning” icon above.  This integrates our Microsoft Web Platform Installer technology, and enables you to easily install platform components on all of your web farm machines.  It also allows you to easily check for any version differences in platform components between your primary and secondary machines in the farm.

Below we can add “ASP.NET MVC 2” to the server farm configuration:


Notice that the “Enable Platform Provisioning” checkbox is selected – this will ensure that products we add to the list are automatically provisioned across all of the servers in the farm.  By default the Web Farm Framework will update each server in the farm one-by-one, and take it out of the load-balancer rotation while it does it, and then automatically add it back into the load balancer rotation once it is complete (ensuring your site never goes down).  The Web Farm Framework will even handle scenarios where a server reboot is necessary – and complete the provisioning step and re-add the server back to rotation once the reboot is done.

Application Provisioning using the Web Farm Framework

The Web Farm Framework enables you to easily deploy and replicate/synchronize Sites, Applications, Content and Settings across a Web Farm.  It uses the Microsoft Web Deploy technology to enable application deployment in an automated fashion (no manual steps required for both adding new applications and updating existing ones).

By default, the Web Farm Framework will automatically synchronize the Sites, Applications, Content and Settings we’ve configured on our “DemoPrimary” server to our “DemoSeconday” server (and any other web-servers we later add to the server farm).  We can use any application deployment mechanism we want to create and copy the application up onto the “DemoPrimary” machine.  This means we could use FTP/SFTP or the Microsoft Web Deploy framework to deploy the sites/content to “DemoPrimary”.  It also means any web applications that use a custom MSI installer or custom batch-file/powershell script to deploy applications onto our “DemoPrimary” will also work.

The benefit of supporting any deployment mechanism is that you can leverage any of the existing application/site/app-pool deployment approaches you already use with IIS to update your primary server – and then use the Web Farm Framework to automatically have the installed application/site/content automatically replicated across the other machines in the web-farm.  This makes it easier to integrate the Microsoft Web Farm Framework into your existing deployment workflows.

If you click the “Application Provisioning” icon in the IIS admin tool you can specify the synchronization frequency with which you want the servers in the web-farm to check for application/site/content updates (by default it happens every 30 seconds). 

You can also optionally specify any additional Microsoft Web Deploy providers you want to use to copy custom settings across machines in the web-farm.  For example, if you want a custom registry setting copied – you can enable that.  If you want to set a custom NTFS security ACL – you can enable that.  If you want to copy/register a COM object – you can enable that.  If you’ve built your own custom “FooProvider” to do some custom stuff – you can enable that too.


When you make changes or updates to applications on your primary server, the Web Farm Framework will automatically synchronize and copy them to the other servers in the server-farm for you.  No manual steps required.

Running Operations and Managing the Server Farm

The Web Farm Framework includes some built-in management infrastructure that allows you to check on the health of a server, and track its status.  You can also use a product like Microsoft System Center (or any custom monitoring software or scripts you have) to monitor the server status within the farm.  If you are using ARR for load-balancing, it also supports a bunch of monitoring and load-balancing settings that allow you to dynamically shift loads across the farm based on server performance and available utilization.

The Web Farm Framework also supports a “Server Farm Operations” task link within the IIS Admin Tool (on the right-hand side of the tool) that you can use to easily run commands across the server farm.  For example, we could flash a command to all the servers in the web farm to ensure that a “MyCustomWindowsService” is started and running using the screen below:


You can also fully automate tasks using PowerShell scripts.


You can take advantage of the Microsoft Web Farm Framework to simplify the provisioning and deployment of your web server infrastructure – both the servers themselves, as well as the web applications and sites you run on top of them.  It enables a smoother continuous deployment workflow.  It also makes it easy to seamlessly scale your infrastructure by adding servers to it without additional management overhead.  Best of all it is available at no extra cost and works with all editions of Windows Server.

Click here to learn more about the Microsoft Web Farm Framework. You can download a beta of the Microsoft Web Farm Framework here.

Tuesday, September 07, 2010

Silverlight 4 service release

Microsoft released a service release of Silverlight 4 last week.  The update build is 4.0.50826.0 and you can find all the details about it at KB2164913.

The primary changes are;

    • SDK feature to enable Add New Row capabilities in DataGrid control
    • Improving startup performance of Silverlight applications
    • Adding mouse wheel support for out-of-browser applications on the Mac platform
    • Various media-related fixes around DRM content
    • Fixed memory leak when MouseCapture is used
    • Fixed memory leak for DataTemplate usage

For end users

For end users, having them simply install the runtime will provide them with the updated bits and benefits of the fixes/features in this service release.  The best way to force encourage your users to upgrade to this service release would be to leverage the MinRuntimeVersion attribute of your object tag:


Notice lines 5 and 6 above.  This would trigger that the end user is required for your application to run and require them to upgrade. The minRuntimeVersion/autoUpgrade are the minimum to require your user to upgrade to the later version.  Ideally you would follow good installation experience guidance (see “Installation Experience Whitepaper” with complete sample source code) to customize your install and/or upgrade experience.

For Developers

If you are a developer and authoring Silverlight applications you may want to grab the new developer bits and updated SDK:

I would install the developer build first and then the SDK and you’ll have a refreshed environment. 

Note that when you now create a new project you’ll be using the new SDK and so the minRuntimeVersion (see above) of the project templates as well as compiled bits for your SL4 application will be using/requiring the updated runtime.

There are NO Visual Studio tools updates for this release so the Silverlight4_Tools.exe package is not needed to re-install.


Tim Heuer’s blog Method ~ of ~ failed,