May 2007 - Posts
I am giving a lecture about Enterprise Library 2.0 and 3.0 for a customer later this month, and spending the last few days building a demo application (Expect more details and posts about this later).
I ran into a problem with the configuration tool the minute I started working with it: The configuration editor always place the assembly definitions of the assembly as signed assemblies. For example:
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
Running the application (Web or Win) always raised the following exception: "Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)".
I even recorded a video myself creating a sample project, calling for help.
Thanks to Olaf Conijn and Hanz Zhang (Test Lead for Enterprise Library), I can now get back to work. It turns out that when you install Enterprise Library 3.0 (or 3.1), you actually get two distinct copies of the library. One copy is in the form of pre-compiled binaries - by default these get installed to "C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\bin". The other copy is in the form of source code, which by default will be compiled and the assemblies coped to "C:\EntLib3Src\App Blocks\bin".
While both copies of Enterprise Library contain identical code, there is one critical difference: the pre-compiled binaries are strong-named (with a Microsoft key that we do not ship), and the assemblies compiled from the source code are not initially strong-named. So as far as .NET is concerned, these two sets of assemblies are completely different and completely incompatible with one another.
I wish I had read Tom Hollander's post: Avoiding configuration pitfalls with incompatible copies of Enterprise Library, that talks about this issue.
When I created the solution, I referenced the assemblies in "C:\EntLib3Src\App Blocks\bin", while the integrated configuration editor added settings using the singed assemblies in "C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\bin". In order to solve this, I had to set the EnterpriseLibraryConfigurationSet property to "Entlib3Src" in the solution properties.
Enjoy!
After some bug were spotted in the latest release of Enterprise Library 3.0, and a promise from Tom Hollander, the team has released Enterprise Library 3.1 to the web.
Here are the highlights of the new version:
Policy Injection Application Block
- The default Remoting PolicyInjector can now be replaced with alternative interception mechanisms via configuration without modifying the application block code
- Call Handler attributes are now honored correctly when placed on interface methods
- Fixed an issue that could cause duplicate handlers where matching rules matched both a class and its interface
- Classes implementing COM interfaces (including those deriving from System.Windows.Forms.Form) can now be intercepted
- TraceLogEntry class is now serializable, allowing it to be used with the MSMQ Trace Listener
Validation Application Block
- Fixed an issue that prevented the PropertyComparisonValidator from working with the Windows Forms integration adapter
- The message template for the PropertyComparisonValidator can now be saved using the configuration tools.
Data Access Application Block
- Connection strings for OLEDB and ODBC connections can now be edited using custom dialog boxes from the configuration tools
The new version is already adopted in the Smart Client Software Factory v2 - May 2007, that was released earlier this week.
Enjoy!
The workflow designer lets you visualize workflows in Visual Studio while building or debugging workflows. You can also re-host the designer in you Windows Forms application to let the users view workflow as they occurs, or customize workflow for their needs. This feature can provide flexibility into your business workflows.
A more detailed description about re-hosting the designer can be found in this MSDN Article. A new sample of re-hosting the designer is also available here.
.gif)
Enjoy!
In the last few days I was helping Nicolas Merlet from MERLET - IT Consulting & Web Development to translate the installation page of his new Windows Live Messenger Add In for On Screen Display.
As it says:
This free add-in enables «On Screen Display» for Windows Live Messenger. This feature allows you to read all incoming messages directly on your screen, without having to open any conversation window ! You can answer a bit later to your contacts, while still being informed of what they are saying ! This way you are less disturbed at work...

Click for a full size image!
Enjoy!
TableAdapterManager in ADO.Net Orcas
There is a number of problems that every project I've ever been involved in has to face. One of them is the order in which records has to be updated in the database when dealing with Master-Detail tables with relations.
Lets say we have a very simple DataSet with Orders and Order Details tables (taken from Northwind).
If I want to add a new Order with Details, I will probably have a code very similar to the following:
OrdersDataSet
dsOrders = new OrdersDataSet();
// Get Data
OrdersTableAdapter ordersAdapter = new OrdersTableAdapter();
ordersAdapter.Fill(dsOrders.Orders);
Order_DetailsTableAdapter detailsAdapter = new Order_DetailsTableAdapter();
detailsAdapter.Fill(dsOrders.Order_Details);
// Perform changes
// Insert a new Order (Parent Table)
OrdersDataSet.OrdersRow newOrder = dsOrders.Orders.AddOrdersRow("ALFKI", 5, DateTime.Now, DateTime.Now, DateTime.Now, 3, 32.3800m, "Vins et alcools Chevalier", "59 rue de l'Abbaye", "Reims", "RJ", "05454-876", "France");
// Insert a new Order Details (Child Table)
dsOrders.Order_Details.AddOrder_DetailsRow(newOrder, 11, 14.0000m, 12, 0);
// Update the parent table first, than the child table
int ordersUpdated = ordersAdapter.Update(dsOrders.Orders);
int detailssUpdated = detailsAdapter.Update(dsOrders.Order_Details);
Note: I updated the Orders table first (Parent table first) and then updated the Order Details table.
If I want to delete an order, I'll use the following:
// Delete an order
foreach (OrdersDataSet.Order_DetailsRow detailsRow in
dsOrders.Orders[0].GetOrder_DetailsRows())
{
detailsRow.Delete();
}
dsOrders.Orders[0].Delete();
int detailssUpdated = detailsAdapter.Update(dsOrders.Order_Details);
int ordersUpdated = ordersAdapter.Update(dsOrders.Orders);
Note: This time, I deleted rows from the Order Details table first and then deleted the master row from the Orders Table.
Now, in what order should I update the database in order to perform all of the above changes together? Over my yeas of experience I've seen many different solutions for this problem which all ended with tricky code that can be sometimes hard to maintain.
In Orcas, Typed Datasets will support the Master - Details Updates out of the box. A new class called TableAdapterManager has been added to the Typed DataSet generated code which has a method called UpdateAll(). This UpdateAll() method will figure out changes made to the DataSet and send updates, inserts and deleted in the right order and in the same transaction.
Using the TableAdapterManager, the code for updating Master - Details changes will be:
// Insert a new Order (Parent Table)
OrdersDataSet.OrdersRow newOrder = dsOrders.Orders.AddOrdersRow(...);
// Insert a new Order Details (Child Table)
dsOrders.Order_Details.AddOrder_DetailsRow(newOrder, ...);
// Delete an order
foreach (OrdersDataSet.Order_DetailsRow detailsRow in
dsOrders.Orders[0].GetOrder_DetailsRows())
{
detailsRow.Delete();
}
dsOrders.Orders[0].Delete();
OrdersDataSetTableAdapters.TableAdapterManager taManager = new TableAdapterManager();
int totalRowsUpdated = taManager.UpdateAll(dsOrders);
You can download a sample project that shows the usage of TableAdapterManager. This project is written in Beta 1 time, so there might be changes in later versions.
Enjoy!
Orcas Datasets - Separate Datasets from TableAdapters
In Visual Studio 2005, we were introduced to the new DataSet Designer, that also generated a TableAdapter for each DataTable in the DataSet.

Along with this great way of creating Data Access Layer for easily, there was a big problem. The Table adapters and the generated Data set are inseparatable which means that when you expose your business entities to the client side or another services, you also expose your data access layer with the connection info inside. This is both a security issue and a software engineering problem.
After receiving some feedback about these problems, Visual Studio "Orcas" can help us with that. The new DataSet Designer has a new property called DataSet Project, that lets you specify a project in which the generated DataSet and table will be created.
With this feature you can easily separate between the Data Access Layer components (the Table Adapters) and the generated business entities. This can help you expose your business entities without exposing your DAL and your connection info.
Enjoy!
Continuing my journey in Enterprise Library 3.0 mysterious ways, I decided to check out the Policy Injection Application Block. Tom Hollander announced this block in February this year, and it immediately caught my eyes...
I am going to take some blog posts to talk about this new block, and will address the following topics:
- Introduction to Policy Injection Application Block (This post)
- Configuring Policies, Matching Rules and Call Handlers
- Implementing a Custom Matching Rule
- Implementing a Custom Call Handler
- Maybe more...
So, without wasting any more time, lets get started...
The basic Idea of Policy Injection is to enable intercepting calls to methods and configuring a chain of handlers that will be executed before and after the real method is being executed. I think that is is best explained in the the following diagram (courtesy of Tom Hollander).

In order to use this Policy Injection mechanism, objects must be created using a special factory that examines the configured policies / matching rules and create the chain of handlers if needed. The consuming program receives back a transparent proxy the the new instance with the chain of handlers ready to use.
For example:
OrdersManager mgr = PolicyInjection.Create<OrdersManager>();
Order order = mgr.CreateOrder("USD", 2.0);
In order to be able to use this interception mechanism, the type that you want to inject policies into must implement one of the following:
1. Inherit from MarshalByRefObject (same base class as in Remoting)
public class OrdersManager : MarshalByRefObject
{
public Order CreateOrder(string currency, double amount)
{
...
}
}
// Create an instance of OrdersManager and use it
OrdersManager mgr = PolicyInjection.Create<OrdersManager>();
2. Implement an Interface
public interface IOrdersManager
{
Order CreateOrder(string currency, double amount);
}
public class OrdersManager : IOrdersManager
{
public Order CreateOrder(string currency, double amount)
{
...
}
}
// Create an instance of OrdersManager and use it
IOrdersManager mgr = PolicyInjection.Create<OrdersManager, IOrdersManager>();
Order order = mgr.CreateOrder("USD", 2.0);
Note the difference between the 2 code snippets that are displayed here, and notice the generic type arguments used in each one of them.
Another important thing you should now that the factory that creates the object and the handlers chains was designed to work efficiently: First, it caches the objects chain and if another instance of the same type is created than there is no need to build it from scratch. Second, it will check if there are any policies configured (more details in a later post), and if there are none, the real object will returned and not a transparent proxy.
There are a few Call Handlers shipped with Enterprise Library that provide implementation for several crosscutting concerns which happen to be implemented with the other application blocks in Enterprise Library. There are Call Handlers for validation, logging, exception handling and many more. Of course you can build your own Call Handler, but I'll leave it to another post.
In the next post I will talk about how to configure Policies with Matching Rules and Call Handlers. Stay tuned for this post series...
Enjoy!
I always say that a developer cannot know everything and be fully updated with technology. In my opinion a developer should choose several technologies / tools / areas and develop an expertise in them, instead of knowing everything not deeply.
When WinFX (later to become .Net Framework 3.0) came along I had chosen to be an expert in Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF), and let someone else pick up Windows Presentation Foundation (WPF).
Recently I have joined a new project that looks into WPF to see whether the presentation layer should be developed with it. As a member of the Architecture Team of the project, and as the Technology Lead of it, I finally have a good reason to start playing with WPF. So, expect more posts on this later.
Regarding Visual Studio "Orcas" - I started working with the VPC version, but a week ago downloaded the self-extracting version and now working side by side with Visual Studio 2005.
As Tim Sneath (Client Platform Technical Evangelist) says:
"Orcas" has a ton of new features for WPF development over the releases that we shipped as extensions for Visual Studio 2005. It's got true WYSIWYG support for XAML code edits, it's got the new Property Editor checked in (shared with Expression Blend), it has far better Intellisense support for XAML, and it's much better for layout.
Since Orcas has a better Cider (WPF Designer for Visual Studio) version in it, I chose to learn WPF straight in Orcas, and skip Visual Studio 2005 at all.
I found an important post in the WPF Designer ("Cider") MSDN Forum about the features included in [Beta1] and the features that don't.
Stay tuned for more posts about WPF as I document my findings...
Enjoy!
Since I blog a lot, and mainly focus on some specific technologies, I found myself always repeat the same links over and over in my posts.
For example:
Visual Studio "Orcas", currently in Beta1 contains some integration between Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) and also some nice features of ADO.Net Entity Framework.
I used a few links in the above sentence that I used in almost every other posts as well. I always create the same links over and over again.
Apparently, Community Server has a nice solution for this, called Blog Snippets:
Snippets allow you to quickly create links in your blog posts and pages using simple replace text. Rather than typing that URL each time you want to use it you can create a snippet instead and have Community Server automatically replace the text.
To manage your blog snippets, go to your blog dashboard, and choose Manage Snippets under Manage Contents menu.
Every snippet contains 3 properties:
Link - The link to the resource / page.
Text - The text that replaces the snippet
Name - The name that you type in the blog post, which will be replaced with the Text with the provided link.
So, after creating the above snippets, I can simply write the same sentence like that
and the result will be:
Visual Studio "Orcas", currently in Beta1 contains some integration between Windows Communication Foundation and Windows Workflow Foundation (WF) and also some nice features of ADO.Net Entity Framework.
Very nice feature, and very useful. At least, for me it is...
Enjoy!
I have been playing a lot lately with the Web Service Software Factory (Service Factory), specifically with the WCF guidance that ships with it, and in the last few weeks I have been providing feedback on the next version of Service Factory (currently called v3).
The other day I got into the Service Factory Home Page on Codeplex and wanted to give more feedback. I noticed the following sentences by Don Smith regarding the releases for v3:
- It is very likely we will not be able to:
- Ship a single release that works on both VS 2005 (Whidbey) and VS 2007 (Orcas). This probably won't be possible for technical reasons.
- Ship 2 releases: one for 2005 and one for 2007. This is just way to costly for our team(time and money).
So, with that in mind, knowing we will ship on November 15th (approximately a month after 2007 is released), what version of VS would you prefer the final release support?
Only a month ago, I read an article called Microsoft Visual Studio Orcas: Maybe in 2007, maybe not. But now, after the ADO.Net team has cut off the ADO.Net Entity Framework from this release, maybe the timeframe has changed.
Although nothing is official yet, I think this is good news.
Enjoy!
The latest version of the Windows Workflow Foundation Hands On Labs was released back in June.
Many customers have asked me to update them whenever the release version is out, so...
here they are (16.3 Mb).
Enjoy!
On the same day Visual Studio "Orcas" Beta 1 was released to the web, I downloaded and played with it (1, 2). Although I have a Dell D620 laptop (Core Duo, 2Gb RAM), I found it very slow and unproductive to run the CTP on a Virtual Machine.
I decided to download the self-extracting installation files of Beta 1 and install it on my main host, side by side with Visual Studio 2005. Before getting this decision, I found a great post by Peter Bromberg that already tried them together and reports some good results.
I Updated my post about Visual Studio "Orcas" Beta 1, and supplied quick download links for the self-extracting version. I am using Free Download Manager as a downloading tool, which helps me to download large images like Orcas, in a couple of hours only. Recommended!
Enjoy!
My recent article was posted today on codeproject. This article introduces the integration between Validation Application Block (part of Enterprise Library) with Windows Communication Foundation (WCF).
You can find the article here, under the unedited articles section.
I'd like to hear any feedback you may have.
Enjoy!