Adrian Alonso

How-to get the XML representacion of a DSL Model Element

Today I had to find out how to get the XML representacion of a DSL Model Element. Here you have an extension method for Model Elements (mels) that gets the concrete serializer using the Domain XML Serializer Directory and the Domain Class Id of the target Model Element (mel).

        public static string GetXML(this ModelElement mel)
            StringBuilder xml = new StringBuilder();
            DomainXmlSerializerDirectory directory = new DomainXmlSerializerDirectory();
            directory.AddBehavior(<#Yours DSL Serialization Behavior goes here #>.Instance);
            // Gets the serializer of the Mel
            DomainClassXmlSerializer serializer = directory.GetSerializer(mel.GetDomainClass().Id);

            if (serializer != null)
                using (XmlWriter writer = XmlWriter.Create(new StringWriter(xml)))
                    serializer.Write(new SerializationContext(directory), mel, writer);
                Trace.TraceWarning(Resources.UnableToGetSerializer, mel.GetType().Name);

            return xml.ToString();
Clarius T4 Editor is out!

The beta version is available at You can go, download it and provide some feedback at the Clarius T4 Forum which will be very valuable for us (Clarius) to prioritize the most important features for the RTM version!


Here is you have the  links:

Victor's officil announcement
Clarius T4 Editor Site
Clarius T4 Editor Forums
Clarius T4 Editor Download


Clarius is Hiring!

As Pablo said in his post Clarius is looking for candidates to fill Senior Dev Positions. You can check the details in Pablo's post too and if you are interested you can ping Pablo, me (alo AT clariusconsulting DOT net or through the contact form of this blog) or send your resume directly to Clarius job alias (which you can find in


runas cmd makes your life easier

This week I had to temporaly use a different user on my machine. So at first I thought I had to move all my settings (outlook profile, firefox bookmarks, vms, etc) from my primary user to this new one. This is not a nice task. Hopefully I remembered the runas command which allowed me to run the above programs (indeed I'm currently creating this post running WLW using runas) as my primary user from the new user session. IMO this is definitily a very good tip if you have the same scenario in the feature.

Posted: Sep 27 2007, 04:37 PM by adalon | with 5 comment(s)
Filed under:
Read source code to be a better developer

I want to give it a try. My idea is to take a look at one or two projects every week and post some conclusions of what I could learn of them. Here you have for example the latest Scott Hanselman's post showing his weekly results.  So if you have in mind a really cool source code stuff, please feel free to ping me (leaving a comment to this post or using the contact me link) and let me know where I can get it!  Thanks!

Posted: Sep 26 2007, 12:37 PM by adalon | with no comments
Filed under: , ,
Adding a custom VS Task List Token

You probably used the TODO task list token to add a comment about what it should be done. But what about if you want to use a custom token to add a different kind of comment; for example a Review(x) comment. VS allows you to add custom task list token via Tools->Options->Environment->Task List as it's shown in the following screenshot:

So then you will able to add the Review comments and these will be appearing in the Task List comments section:

TCI - Toolbox Controls Installer


TCI is a VS Package that is provided by the VS SDK as a redist. TCI allows you to easily add your custom Control to the VS Toolbox. For a brief introduction to TCI you can check the VS SDK documentation. Here I will try to cover what is happening under cover:

When you want to add your custom control to the VS toolbox using the TCI VS Package all you need is to tell TCI where the assembly containing the control is and notify to TCI this event incrementing a registry key. Probably the easier way to achieve these requirements is using a WIX-based installer (as the SDK sample does).

In order to tell TCI where your control is you can use the the fully qualified type name if you are installing the control in the GAC as following:

<Registry Root="HKLM" Key="Software\Microsoft\VisualStudio\9.0\ToolboxControlsInstaller\GacControl, Version=, Culture=neutral, PublicKeyToken=1631b3e7a8fbcce5, processorArchitecture=MSIL" Value="Litware Controls" Type="string" />

Or provide a location where the assembly containing the control is using the CodeBase value:

<Registry Root="HKLM" Key="Software\Microsoft\VisualStudio\9.0\ToolboxControlsInstaller\NonGacControl, Version=, Culture=neutral, PublicKeyToken=1631b3e7a8fbcce5, processorArchitecture=MSIL" Value="Litware Controls" Type="string">
<Registry Name="Codebase" Value="[#AssemblyContainingTheFile.dll]" Type="string" />

Finally you have to include the MSM containing the custom actions which notify TCI that a new Control has been installed:

<Merge Id="TbxCtrlsInstDefaultItemsCA" Language="1033" SourceFile="..\..\..\Redistributables\TbxCtrlsInstDefaultItemsCA.msm" DiskId="1" />

The custom action will increment or decrement the "Default Items" value of the following registry entry:

"Default Items"=dword:00000001

Note that the {2c298b35-07da-45f1-96a3-be55d91c8d7a} is the GUID for the TCI VS Package.

It's important to check if the TCI Redist is already installed before installing your custom controls if you targeting VS 2500. It's not necessary for VS codename "Orcas" because TCI Package is already installed. You can find the TCI VS Package in the VS's Private Assemblies directory. 

Why a good error message is important

This post was originally published at


I was trying to change my private email in one of the forums I'm subscripted. The thing is that after clicking the save button it said:

"Sorry, an Error has Occurred"

"Unfortunately an error has occurred during the processing of your page request. If you were attempting to submit a new post, your post may not have been recorded. Please accept our apologies for the inconvenience."

And some links to go back, help, etc. No helpful at all. I searched through the forum posts to find out if someone had has the same issue and I found that the private email address couldn't be duplicated. In that moment I remembered I had another user with that address so I could take the steps to be able to change it in a few seconds. If the error message had been something like "The email address is being used by another user. Please choose a different mail and try again" it would be a significant save of time.

The cause of the error is probably due to they are not validating the email address, so after receiving the generic sql error they show the generic (not useful at all) "Sorry, and Error has Occurred". 

Posted: Aug 27 2007, 03:41 PM by adalon | with no comments
Filed under: ,
"Organize Usings" in VS code name "Orcas" ala Eclipse

This post was originally published at


Those that have used Eclipse will probably miss the ctrl+shift+o shortcut ("Organize Imports") when you switch to VS. But now VS code name "Orcas" provides a "new" feature (which unofficially existed in Whidbey) that allows you to remove and sort usings:

So if you don't want miss the Eclipse feature anymore you can add the shortcut going to Tools->Options->Environment->Keyboard

Search the RemoveAndSort command and press the ctrl+shift+o combination. Note that the shorcut is currently used by the OpenProject command and it will lost if you confirm to use the combination for the RemoveAndSort command. 

Posted: Aug 15 2007, 10:56 PM by adalon | with 4 comment(s)
Filed under: , ,
GAX 1.3 is out!

This post was originally published at


This new version of GAX is a must if you are thinking to develop Guidance Packages using VS Codename "Orcas" (previous version of GAX didn't work with the latest version of VS) and it will also provide some new features if your are developing with VS 2005.

A welcomed “fix” is the enhancement of the registration process. Now it's smarter about whether to install VB templates based on the presence of VB as a Visual Studio's product. This means that if your Guidance Package contains VB templates (.vstemplates for VB projects or items) you won't need to add conditional logic in your installer to avoid the registration failure when the package is being installed or registered.

The GAX installer is also improved to use WIX technology but the GAT installer project that is unfolded when you create a new Guidance Package using GAT is still the same VS Setup Project.

At last, the Experimental Hive registration is now a built-in feature in GAX allowing you to register your Guidance Packages in both Normal and Experimental hives.

So it seems that this CTP is a necessary and welcomed update for the runtime but not for the UX of developing Guidance Packages.

Here you have the links:

- Grigory Melnik's announcement
- GAX July 2007 CTP download
- GAT July 2007 CTP download

Posted: Aug 05 2007, 11:01 PM by adalon | with no comments
Filed under: , , , , ,
More Posts Next page »