All posts by Jonathan Cisneros

Associating a URL Protocol to your Application

This is something done by WebPI (wpi://) and many p2p apps that you can do with your own application also: associate a URL protocol to your application. Let’s say you want to use URLs beginning with myapp:// to launch your own application and perform a certain task (i.e. download a file and open it). This is simply done by adding some entries in the registry, the following steps guides you on how to configure your setup project to do this.


  1. Right click on the Setup project of your solution, go to View and select Registry.
  2. Under HKEY_CLASSES_ROOT create a new key and use the name for your protocol, let’s say “myapp“.
  3. Add a new String value and delete the name, now it should appear with the name (Default).
  4. Set the value to “URL:myapp Protocol”.
  5. Add another String value and name it “URL Protocol“. Leave its value blank. The registry view should now look like the following screenshot:
  6. Under the “myapp” key created on step 2, create a new key and named it “shell“.
  7. Under the “shell” key create a new one named “open“.
  8. Under the “open” key create a new one named “command“.
  9. Add a new String value under the “command” key and delete its name to make it the default value.
  10. Set the default value to ““[TARGETDIR]MyApplication.exe” “%1”“. The registry view should now look like the following screenshot:

That’s all!, each time the user hits a URL with your custom protocol, your application will be executed and will receive the URL. Now you have to parse it and act accordingly.

Additional reading: Registering an Application to a URL Protocol

Troubleshooting Windows Azure Deployment

Usually, when Windows Azure fails to initialize the services, the portal shows the services cycling between the Initializing, Busy and Stopping states and it gets stuck in an infinite loop between these states. The following list are the most common causes for a deployment to Windows Azure may fail (even if it works locally) and how to fix them:

  1. Missing referenced assemblies: set CopyLocal = True for referenced assemblies not in .NET Framework 3.5 or Microsoft.WindowsAzure.ServiceRuntime (these assemblies are the only ones present in Windows Azure).
  2. Project built for 32bits only: Use Platform target = Any CPU (or x64). Windows Azure runs on 64 bits. 
  3. Path too long: Use project names with less than 28 characters. Sometimes no exception is shown, to know if this is the issue, exclude all the roles but one from the Cloud Service project and run once each time to be able to view the error details in the output window when running on the Development Fabric. You should see the following error message “ERR: Failed to complete setup of assembly (hr = 0x8007006f)”.
  4. Missing files: Include all the used files in the project. Files that are not included are not published (for instance, images)

If you will perform a service upgrade, first suspend it. If you do not suspend the service and you perform an upgrade, it will never end. Apparently, it tries to return to the previous version state as part of the upgrade process, if our new version has the same issue (fails to initialize by iterating between the stopping to initializing states), it will get stuck in the middle of the process and you won’t be able to perform any action from the Azure portal, you cannot even delete the service. If this happened to you, you can try using the Azures Cmdlets to set the deployment status.

If you continue having issues, the following blog post includes more possible causes and suggestions:

Microsoft Web Platform Installer: Version 2.0 RTW live

The new version 2.0 of the WebPI is now available to download from the Web Platform portal and it includes the following new features:

  • An options dialog where you can:
    • Select addition scenarios to see more products for installation (Media, Developer Tools tabs).
    • Add more product list feeds (You can add your customized feed!)
    • Select your preferred language from a list of 9 supported languages.
    • Clean the installer cache folder.
  • Downloads are cached so you don’t have to re-download when installation fails (then you can clean the cache from the options)
  • Improved validations for you to get improved error messages.
  • Includes the no. of downloads and the rating for each product.
  • Ability to sort alphabetically, by popularity or by rating.
  • Many bugs fixed.

Now is not only more easy to install your applications but also to quickly explore and choose the right one!

Microsoft Web Platform Installer: Simplifying Installations

This is a common scenario:

You need to install the product X, so you go and download it. Once you have executed the installer a warning message is shown about the missing dependency Y, so you search it on internet and when you find it you discover that it requires Z but you don’t worry because you already have it installed, moving on, you download and run the installer of Y, but then it comes that it required a newer version of Z… The never ending story! Your blood pressure raises to the clouds and you crash the keyboard against the screen, kick the box and whatever is under the desk, take the first heavy thing you find and throw it thought the window, and you see your pet on the sofa so you… relax! Don’t do it! The Web Platform Installer (Web PI) has come to save your physical integrity and people near you. How?: It greatly eases the entire labor of installing a product including every task that may require to get it to work.

So the Web PI is a sort of:

  • Catalog of free Microsoft applications, frameworks and tools: you can use it to browse and find a bunch of Microsoft products available to install.
  • Dependencies checker: it is capable of checking the supported environment and the entire dependencies tree of a product.
  • Downloader manager: it takes care of finding and downloading each of the files needed to install the products you want.
  • Full installer: not only installs the product you choose but also all of the required dependencies for it to work and it makes all the job almost unattended.
  • Setup wrapper: it can create a facade over the installer process to show its own custom UI for a nice integration between the installer (it could be an EXE, MSI, MSU or ZIP file) and Web PI.
  • Updater: Web PI uses an ATOM feed to keep up to date its catalog of products so you can install the newest version of your products.
  • IIS Configurator: If you installs a web application that requires installing/enabling certain IIS componentes/roles, Web PI will do it for you.

Ohh!… How I wished to have all of this stuff for installing Team Foundation Server!!!

You can download it at the Microsoft Web Platform portal:

Once you have installed the Web PI you can use it to browse the available applications to install. You can also browse the Web App Gallery and install any application by just clicking on the “Install” button which will launch Web PI with the product selected waiting for your confirmation to install.

Notice that the Web PI is restricted to the currently available Microsoft products (free developer tools and web applications) and is not aimed to be used as an installer for your own products.

Also I’d recommend to read this post from Scott Guthrie to find more details and screenshots.

I hope you can take advantage of the Web PI as much as I did. I will continue posting about Web PI for you to know how it works and how to get the best from this tool, so be tuned!

Webcast Desarrollando para Office 2007

El 21 de Mayo expusimos junto a Ezequiel Jadib un Webcast sobre Visual Studio Tools for Office para Microsoft Student Partners de latino america. Agradecemos a Sebastian Renzi, Juan Pablo Garcia y Damian Schenkelman quienes nos brindaron excelentes tips para la presentación.

Lo temas vistos fueron:

  • Introducción a Visual Studio Tools for Office (VSTO)
  • Introducción a OpenXML
  • VSTO para Outlook
  • VSTO para Excel
  • Office Ribbon

Para descargar el material de la presentación:

Información adicional sobre VSTO:

Windows Azure: Everything in the cloud

These days we are seeing the dawn of a new computing generation, that is the 5th generation of computing. The first one were monolithic applications, then came the Client-Server and tiered applications, and currently we are building Web-based and SOA applications, today, the new buzzwords are Services and Cloud computing.

The past week, on PDC (Professional Developers Conference) event, Microsoft announced Windows Azure, a big initiative on the new computing generation. Windows Azure is a “cloud services operating system”, this is, a platform for developing, hosting and managing applications and services in the cloud. Being in the cloud, means that it is hosted on and available from internet, in this case, the hosting service is provided by Microsoft’s datacenters.

But that is not all, Windows Azure is just the lowest level of the Azure Services Platform, this platform includes several services running over Windows Azure, like:

  • Live Services: allows to create rich applications to run on a variety of platforms and devices.
  • .NET Services: includes:
    • Service Bus: provides a secure, standards-based messaging infrastructure to communicate application components even across organizational boundaries.
    • Workflow Service: hosts and runs workflows on the clouds and provides specialized activities for communication using HTTP and Service Bus.
    • Access Control: integrates standards-based identity providers, including enterprise directories and web identity systems such as Windows Live ID.
  • SQL Services: Stores data in the cloud using ACE structure (Authority, Container, Entity), the entities are flexibles and you can access the data using several standards-based interfaces (SOAP, REST, …).

Being part of this extraordinary family that we call Southworks, gave me the opportunity to learnt about these new technologies and participate in the development of a new set of Hands-On Labs about Azure Services Platform for the PDC event. For downloading this HOL go to: Azure Services Training Kit – PDC Preview.

For further reading:

.NET Framework 3.5 and Visual Studio 2008 SP1 released!

It’s awesome how fast time goes, a year ago, I was playing with .bat files (like putting messages in the autoexec.bat file), a month ago, I was building applications to do my accounting homework at highschool using C++ Builder, a week ago, I was making simple games with Visual Basic 6 and then working with the same tool, yesterday, I was trying to learn the big .NET Framework 1.1 and fighting against ADO.NET (20 lines to do the same thing that I used to do with three lines in ADO 6!), an hour ago, I was building ASP.NET 2.0 web sites and envying the toys from the RoR and J2EE guys, now, a minute ago, I helped to create the Training Kit for the .NET Framework 3.5 SP1 that seconds ago was released the final version.

A bunch of exiting things are included in the .NET Framework SP1 like:

You can get the bits at:

ASP.Net Dynamic Data (Scaffolding with .net)

image When you build data centric web applications, a big part of the code is related to the implementation of CRUD (Create, Read, Updated, Delete) operations. Scaffolding is a mechanism to generate fully functional data driven applications based on metadata inferred from a model, basically, all the CRUD operations are implemented by using the metadata obtained for each entity/table in the model, making it a very useful tool for prototyping.

That is what ASP.Net Dynamic Data does, it is a scaffolding technology that uses templates (ASP.Net Web Pages) to dynamically generate functional CRUD pages. Like Ruby on Rails, Dynamic Data makes a high use of conventions to infer how the results will be rendered, but it can be highly customized in an really easy way by adding metadata to the model or modifying/adding templates. This allows to start with a raw prototype and continue customizing and tuning it ’till a mature application.

Getting Started

Once you got the bits installed, you are able to create a new project using one of these two templates:

  • Dynamic Data Web Application: Creates a Dynamic Data web application using a LINQ to SQL data model to generate the scaffolds.
  • Dynamic Data Entities Web Application: Creates a Dynamic Data web application using a Entity Data Model (ADO.NET Entity Framework) to generate the scaffolds.

The main difference between both, is the data model that Dynamic Data will use as data source and to infer the metadata needed to do the scaffolding.

The Data Model

image As said before, the data model can be LINQ to SQL or Entity Data Model depending on the project type selected.

While LINQ to SQL is tightly bound to the database schema (each property is bound to a specific field in a table), Entity Framework is more flexible and loosely coupled and you can query for entities using either LINQ or Entity-SQL.

When creating the data model is recommendable to create a Model folder to place the data model file (.dbml or .edmx) and the additional classes that we will create through the development to enhance the metadata.

Enabling Scaffolding

This is the easiest thing, to enable the scaffolding you just need to modify a simple line of code.

In the global.asax.cs file is a method named RegisterRoutes where you will find a big section of commented description on how to register a data context to be used as the model to generate the scaffolds.

To enable scaffolding for all the classes/tables in the data model, you need to register the model in this way: (un-comment the following line and modify the bold parts)

model.RegisterContext(typeof(Model.MyDataModelContext), new ContextConfiguration() { ScaffoldAllTables = true });

Just modifying the previous line your application is ready to run, just press F5 and enjoy the magic!

If you want to generate scaffolds for specific classes/tables you have to set the ScaffoldAllTables property to false and then decorate the classes you want to scaffold with the [Scaffold(true)] attribute.


Adding Metadata

The generated scaffolds have all the common functions of a data-driven application, the list are filtered, sorted and paged, the fields in the edit and insert forms are validated according to its data types, etc., but it only does the best it can with all the metadata that can retrieve from the data model, therefore you will find that many things that can be improved or refined.

To add metadata to the model, Dynamic Data provides a full set of attributes under the System.ComponentModel.DataAnnotations namespace to be applied to the classes in the data model. But instead of applying the attributes directly over the generated code of the model you have to create partial classes aimed just to add metadata to the model.

Here, we’ll face a problem since a partial class can not redefine a property, thus we won’t be able to add metadata to the properties. This problem is solved by using an inner class and associating it to the data model class with the MetadataType attribute.

The following is a sample of a data model class using an inner class to refine the model:

public partial class Product
private class ProductMetadata
[Required(ErrorMessage = “Product name is required.”)]
[DisplayName(“Product Name”)]

public object Name { get; set; }

[Range(0, 10000, ErrorMessage = “Standard Cost should be between {1} and {2}.”)]
public object Price { get; set; }

Since the inner class porpoise is to add meta data, the properties only need to match in name and not in type (in the sample, all the properties are of object type).

In this post by María Wenzel you will find a list with some of the attributes available: Dynamic Data Attributes.

Customizing the Templates

Under the folder DynamicData you will find all the templates that Dynamic Data uses to generate the scaffolds. You can modify them to change the look and feel, or to add new functions for all the tables, but if you want to customize the templates for an specific table, you can, just follow these simple steps:image

  1. Create a new folder with the name of the table you want to customize under the DynamicDataCustomPages.
  2. Copy from DynamicDataPageTemplates the aspx templates you want to customize (i.e. List.aspx) and paste in the new folder.
  3. Delete the code behind file of the new template (i.e. List.aspx.cs and List.aspx.designer.cs).
  4. Customize the new template at your desire and using all of your creativity.

Notice the use of conventions in this case that allows a friendly development experience. Dynamic Data will look for the templates, first under DynamicDataCustomPages[TableToRender] and then under DynamicDataPageTemplates.


With ASP.NET Dynamic Data you can experience a nice development experience, it is easy to learn and to use. Some people may say that scaffolding is just for prototyping, I agree on that, but I found Dynamic Data very flexible and customizable, you may use it for a part of the application (where only CRUD operations are needed) and, for the rest of the application, continue developing as you are used to. Something that I noticed is a little of lack of performance, I think that it is caused by the use of reflection to get the metadata from the model. Anyway, it is a very interesting and nice framework that worth the try.

.NET Framework 3.5 SP1 – Client Profile

The .NET Framework 3.5 Client Profile is a lightweight subset of the full .NET Framework 3.5 aimed to be deployed in Client machines. Therefore, it only have the assemblies that are commonly used on client boxes and does not contains any server or development related assemblies.

This framework subset weight just 27Mb against the 200Mb of the full framework.

You can get the bits from here: Microsoft .NET Framework 3.5 Client Profile (BETA)

How do you ensure your project will work for the .Net Framework Client Profile?

It’s pretty easy, if you have installed the Visual Studio 2008 SP1 in the project properties you will find a checkbox that allows to target your application to the Client Profile subset.


Visual Studio will verify all the references and will add an exclamation icon on the references that are not available for the client subset, also when building the project, warnings will be displayed for the unavailable assemblies.



If you got the beta version of the Visual Studio SP1 you have to take in mind that the subset list (Client.xml) that Visual Studio uses to validate the references is out of synch from the actually included assemblies (VS generate warnings for some assemblies that really are in the Client Profile). To solve this issue, you may find useful the Justin Van Patten’s blog post: .NET Framework Client Profile.

Technorati Profile

C# 3.0 new features

This post is aimed to be a quick abstract for all the new C# language constructs introduced with the version 3.0.

Implicitly typed local variables

By using var keyword to define a local (does not work at class level) variable is not needed to define its type, the compiler will infer it.


var i = 0;
var intArr = new[] { 0, 1, 2, 3 };

Object and Collection Initializers

Object’s properties can be initialized when creating the object and also the collection items.


TextBox txt = new TextBox() { Text = "John", Width = 200 };

List<string> colorspaces = new List<string> {"RGB", "CMYK", "GreyScale", "B/W"};

Anonymous types

By combining the previous two features (Implicitly typed variables and Object initializers) you can create anonymous types (statically typed, with no name used in the code).


var guy = new { FirstName = "John", LastName = "Doe" };

Automatically Implemented Properties

You can create properties with no need for a private member to store its value.


public string Name { get; set; }

//read-only property
public byte Age { get; private set; }

Extension methods

By using the this keyword in a static method argument you can extend another class. You "injects" methods to an existing class from another one.


public static class ExtensionClass
    //Extension method
    public static byte ToGray(this Color c)
        return (byte)(0.3 * c.R + 0.59 * c.G + 0.11 * c.B);

byte pixelGray = Color.Green.ToGray();

Lambda Expressions

Lambda expressions are like pretty simple functions that takes input parameters and evaluates an expression.


(input parameters) => expression


int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

int oddNumbers = numbers.Count(n => n % 2 == 1);


Func<int, int> duplicate = number => number * 2;