Blake Niemyjski

  • It's the littlest of things that we do, that make CodeSmith shine.

    During each release of CodeSmith, one thing we always do is test upgrade scenarios between each versions and check for backwards compatibility among other tests. Recently, I was amazed at how much change has taken place between CodeSmith 4.x and the latest CodeSmith 5.1.x release when it comes to the user interface. CodeSmith has made a huge effort to make CodeSmith rock solid, crazy fast,  and easy to use. I’d like to give everyone a quick inside look as to how I think CodeSmith has accomplished this.

    Our goal from the beginning was to make CodeSmith a top notch dependable tool. I think we have accomplished this through various forms. In the previous version of CodeSmith a user would have to report every bug they found by using the built in tool, support or the community. We have found that most of the time you’re in a hurry and stop using the tool or don’t report the issue. We have spent the time to make bug reporting much easier and provide us with as much possible as you want us to. So we can fix the bug with as little user intervention as possible. You can also choose in the options to send us feedback automatically, or you can choose the default option to send feedback at your digression.

    When a crash occurred in CodeSmith 4.x you had the option to send in a crash report via the following dialog. We have found that the previous approach doesn’t allow us to reproduce the issue as easily and most of the time doesn’t provide enough information.

    Since the introduction of CodeSmith 5.1.x we have added new functionality to CodeSmith that allows the user to selectively choose which pieces of information are sent back to us.

    If you click on the click here link you will be presented with the following dialog that lets you choose which pieces of information you want to send back.

    This additional information allows our project managers and team see what issues end users like yourself are experiencing so we can get a bug fix out quickly. If you provide your email address, we will contact you and let you know that we are looking into the issue. We have gathered a lot of feedback through the use of error reporting that has changed how we as a company work on bugs in the product.

    User feedback is very important to us. We review all user feedback that comes into CodeSmith via support, surveys, and the community forums. With the latest build of CodeSmith, It has become even easier to contact CodeSmith and let us know what you think. From the Help menu select feedback and you are prompted with the following dialog that allows you to ask a question, submit an idea or bug report. We have also included the functionality to search previous submitted ideas and vote on them.

    You might be thinking to yourself, CodeSmith might be stable, but is it faster with the new release. The answer to that question is YES. We have spent a great deal of time focusing on Template Caching to ensure you never need to recompile a template unless a change has taken place. We have also introduced a new feature we call deep load. Deep loading allows us to grab all your schema information in advance so we don’t need to make multiple round trips back to your database. We have also spent time working with performance and memory profilers tweaking CodeSmith for optimal performance. If you come across a scenario where you think CodeSmith is slow, please let us know by submitting a bug report.

    We have made improvements to the user interface across the board to allow you to know exactly how CodeSmith is working. Take for example, previously when CodeSmith started up you were prompted with a dialog like the following when samples were extracted:

    This dialog would freeze CodeSmith, so naturally you would think that CodeSmith had stopped working. We have since changed this to be multithreaded and also display you a progress bar.

    Another major change we have made is to simplify configuration.

    Can’t you tell this dialog was made by a developer ;). Let us know what you think of the new configuration dialog!

    We love being organized and providing you with all of our samples applications and templates. Below is a comparison between what you would have seen in CodeSmith 4.x and CodeSmith 5.x. Besides adding and updating a lot of the templates. We have now also made it easier to find the template you are looking for.

    In CodeSmith 5.1 we have also included the sample applications to most of the Framework Templates. You can find this in the  Documents\CodeSmith\Samples\v5.1\Projects\Framework-Samples folder on your computer.

    I hope that if you were a previous user of CodeSmith and you try out the latest version of 5.x you notice these major changes as well as the minor changes like threading enhancements so you can navigate around CodeSmith features much quicker.


  • CodeSmith CSLA Templates v1.0 released!

    Over a week ago we released our new CSLA Templates. I highly recommend everyone that uses CSLA to try them out as they will save you a ton of time. Also you'll notice very quickly that it follows the CSLA best practices and has other features that you have been looking for like a working Data Access Layer (DAL). The best part is that you won't have to worry about learning something new (the generated code) if you are already familiar with the CSLA Framework.

    Noteable features:

    • Working data access layer with concurrency support.
    • Support for completely overriding the generated rules.
    • Generates three partial classes per business object.
    • Generates a common business, data and UI layer.
    • Quick start.
    • Implements all 14 object types.
    • Detects and generates properties and child objects for the following database relationships (One to Zero or One, One to One, One to Many, Many to One, Many to Many).
    • All DateTime data types are generated as Csla.SmartDate
    • Correctly handles Binary Database fields (E.G Images, TimeStamp)

    Download the templates

    Download the PetShop sample application

  • Tips & Tricks: Debugging CodeSmith on Microsoft Windows 7

    We have updated the Tips & Tricks: Debugging CodeSmith with the changes needed to debug on Windows7.

    Here is the quick overview of what you need to-do to enable debugging on a Microsoft Windows 7 machine:

    1. Update the Just-In-Time debugger setting DbgJITDebugLaunchSetting.  The setting is found in the registry at [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]. 
    2. Set the value of DbgJITDebugLaunchSetting to 2.
    3. If you are using a 64bit operating system then you must also set the same key (DbgJITDebugLaunchSetting) in this folder [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework] to 2.
    4. If you run into any issues try running CodeSmith Studio and Visual Studio as an administrator.

    Now when CodeSmith enters a break point you will see something like this:

    Visual Studio Just-In-Time Debugger

    Click Yes, debug CodeSmithStudio to continue debugging.

  • CodeSmith CSLA templates - Part 2: The quick start

    In Part 1: The introduction was an overview of the CodeSmith CSLA templates we are developing at CodeSmith. In this post, I am going to go over how to use the CSLA quick start and the new improvements resulting from customer feedback (Keep the feedback coming!).

    First launch CodeSmith Studio and under the Frameworks node open CodeSmith.CSLA. The CSLA.NET folder will eventually be going away and replaced with our in house CSLA templates (CodeSmith.CSLA).

    CodeSmith Studio 

    There are a couple of folders in the CodeSmith.CSLA folder

    Folder Name


    Common Contains the supporting CSLA assemblies and the Visual Studio templates to create the project.
    CSharp Contains the C# templates.
    Source Contains the source code to the quick start and the API that the templates use.
    VB Doesn’t exist yet but will contain the VB.NET templates.

    Now double click on the quick start template, the property grid should now be populated with the quick start properties.

    CodeSmith Studio (4)

    Next select “” button for the Source Database property and select your database you wish to generate against. In this example I will select the PetShop database. The quick start will now populate the property grid most common settings. From here configure the settings to your liking and click generate. Microsoft Visual Studio should now launch unless you set Launch Visual Studio property to false.

    PetShop - Microsoft Visual Studio (Administrator)

    Next right click the PetShop.UI project and select Set as Startup Project

    PetShop - Microsoft Visual Studio (Administrator) (3)

    Now when you select build or debug your project will start generating.

    PetShop - Microsoft Visual Studio (Administrator) (4)

    The UI Project is a place holder project for you to start building your application. So now that you have the general idea on getting up and running quickly with the quick start lets see what it takes to customize the type of each entity. Lets right click the Entities.csp template and select Manage Outputs.

    PetShop - Microsoft Visual Studio (Administrator) (5)

    After the manage outputs dialog comes up double click on the Entities.cst item.

    Edit Output - Entities.csp (2)

    Earlier in the CSLA beta we had 14 different outputs instead of one. Now all the settings are in one output (Entities.cst). Say you wanted to change the types of your entities from an EditableRoot to a EditableRootChild object. Just use the familiar table picker and change it. It will check to make sure there is no conflict and that any child lists are populated. For example if you had no entities selected and you added a table to EditiableChild it would look through all the lists and if a list entity was not found it would add the table to the EditableChildList. This makes it extremely easy to configure your Business objects.

    Please give us your feedback on the new CSLA templates!

  • A fix for the Microsoft .Net Framework 3.5 SP1 Fatal Execution Error (VS Silent Death Bug).

    We released CodeSmith 5.1 with the new requirements of the Microsoft .Net Framework 3.5. One of our experiences in upgrading to the .Net Framework 3.5 is issues we have run into like our customers reporting Visual Studio disapearing or closing extremely quick when they try to generate code using CodeSmith's Visual Studio Integration. The following link (Tools - Part 11 - Add-ins - Attempting to work around the “VS Silent Death” bug) describes this issue in detail. Since his blog content is currently offline I’ll quote his content.

    One very annoying and elusive problem that sometimes slam down on VS2008 / .net 3.5 SP1 developers is the “VS Silent Death” bug. It manifests itself by simply making the Visual Studio IDE ‘disappear’ at a random point such as when opening a project or when opening a certain type of file in Visual Studio.

    The annoying part is the lack of feedback from VS that leaves many baffled. The VS IDE just “disappears” without any feedback, although there is always an entry in the Windows event log (app log) for each crash stating something along the lines of “.NET Runtime version 2.0.50727.1434 - Fatal Execution Engine Error (79FEC5F0) (80131506)” or “.NET Runtime version 2.0.50727.3053 - Fatal Execution Engine Error (7A035E00) (80131506)“.

    The elusive part of the problem is that for some users it happens only on rare occasions, while for others it can occur with relatively high frequency. It can happen for a specific project or solution on one machine while the same project/solution works fine on an identical machine next to it (and vice versa). This makes it tricky to reproduce and troubleshoot “on demand”.

    A mitigating factor is if any tools or add-ins used reference the .net 3.5 framework, so it can happen more frequently when VS add-ins are installed but also when using certain features in VS2008/.net 3.5 such as MVC, Entity Framework, Linq-to-SQL, WPF, etc. The fact that third party add-ins are commonly affected has made it easy to put the blame on the add-ins; Microsoft’s PowerCommands, Huagati DBML/EDMX Tools, Jetbrains Resharper, Ankh, Gallio, and many other third party add-ins have been affected and sometimes blamed for causing the crashes. So has the WPF designer, L2S designer, MVC libraries etc. However, debugging* and research* points to corrupt NGen images and assembly load problems.

    Finally Microsoft wakes up

    There have been numerous reports* to Microsoft on this issue through Microsoft Connect but despite the reporting party supplying crash dump files for several of the reports they have all been closed with “not reproducible”. In fact, until very recently I have not found a single acknowledgement from Microsoft of this bug, even when actively pursuing an answer (i.e. asking them directly). A few days ago a Microsoft blogger, Jim Nakashima, wrote in his msdn blog that they have reproduced it when working with MVC in Azure projects and that the CLR team is working on a fix:

    Fantastic. Great. Terrific.

    So far there’s no “official” acknowledgement from MSFT of this bug or ETA for a hot fix on, or Not even Microsoft’s primary communication channels to the developer community (a.k.a. Scottgu or Scottha’s blogs) mention the problem except in user comments.

    Update: Microsoft has a patch, KB963676 that addresses this issue. After installing it on my repro-system it looks promising; I have not yet been able to trigger the ‘VS death’ after applying the patch. No word (yet) on when it will be publicly available, but I assume that affected parties can request this hot patch through MS Support by referring to the MSKB #.

    Update 2: The patch is now available for download from Microsoft connect. See Jim Nakashima’s announcement at

    Source  (Tools - Part 11 - Add-ins - Attempting to work around the “VS Silent Death” bug).

    The Fix.

    A current workaround for this issue is to apply the following Microsoft patch and reboot your computer.

  • How to register a keyboard shortcut (hot key) in a .NET Windows Forms Application.

    There may come a time when you want to implement some extra features or maybe an Easter egg into your application using keyboard shortcuts. I was recently tasked with creating an Easter egg so we could test some functionality in CodeSmith. After countless searches looking for an elegant solution (I found a few ugly solutions and some nicer ones) I came across Method #3. I’ll First touch on the one I didn’t choose to go with.

    Method #1

    The following code block will make an unmanaged call to the user32.dll to register the hotkey. I would never go this approach, but if you were like me and couldn’t find anything in the time frame allotted then you might end up implementing this.

    First you will need to update your using block.

    using System.Runtime.InteropServices;

    Then add the following code to your form.

    /// <summary> The RegisterHotKey function defines a system-wide hot key </summary>
    /// <param name="hWnd">Handle to the window that will receive WM_HOTKEY messages
    /// generated by the hot key.</param>
    /// <param name="id">Specifies the identifier of the hot key.</param>
    /// <param name="fsModifiers">Specifies keys that must be pressed in combination with the key
    /// specified by the 'virtualKey' parameter in order to generate the WM_HOTKEY message.</param>
    /// <param name="virtualKey">Specifies the virtual-key code of the hot key</param>
    /// <returns><c>true</c> if the function succeeds, otherwise <c>false</c></returns>
    /// <seealso cref=""/>
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint virtualKey);
    private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
    public static int MOD_CONTROL = 0x2;
    public static int MOD_SHIFT = 0x4;
    public static int WM_HOTKEY = 0x312;
    private static int keyId;
    public static void RegisterHotKey(Form f, Keys key)
       int modifiers = 0;
       if ((key & Keys.Control) == Keys.Control)
           modifiers = modifiers | MOD_CONTROL;
       if ((key & Keys.Shift) == Keys.Shift)
           modifiers = modifiers | MOD_SHIFT;
       Keys k = key & ~Keys.Control & ~Keys.Shift;
       Func<bool> ff = () =>
                               keyId = f.GetHashCode();
                               RegisterHotKey(f.Handle, keyId, (uint) modifiers, (uint) k);
                               return true;
       if (f.InvokeRequired)
    public static void UnregisterHotKey(Form f)
           Func<bool> ff = () =>
                                   UnregisterHotKey(f.Handle, keyId);
                                   return true;
           if (f.InvokeRequired)
       catch (Exception ex)
    protected override void WndProc(ref Message m)
       base.WndProc(ref m);
       if (m.Msg == WM_HOTKEY)
           throw new Exception("You found an Easter Egg.");

    Then in your Form Load event add the following code.

    Keys k = Keys.F2 | Keys.Control;
    RegisterHotKey(this, k);

    I found this example here, Please note that I did some refactoring to it.

    Method #2

    I also found this WPF solution that I haven’t tried but should work. This looks like the best approach for implementing this functionality in WPF as I have seen people use the first method.

    public WindowMain()
       this.InputBindings.Add(new InputBinding(MyAppCommands.SaveAll, new KeyGesture(Key.F2, ModifierKeys.Control)););
       CommandBinding cb = new CommandBinding(MyAppCommands.SaveAll);
       cb.Executed += SaveAllDocuments;
       this.CommandBindings.Add(cb );
    private void SaveAllDocuments(object obSender, ExecutedRoutedEventArgs e)

    Method #3

    The approach I went I thought was the best way as it is small and elegant piece of code. It is completely safe to implement as it doesn’t have any hooks into native windows dlls. The initial idea came from here, to implement this code just place it anywhere in your Form.

    protected override bool ProcessCmdKey(ref Message message, Keys keys)
        switch (keys)
            case Keys.F2 | Keys.Control:
                //Process action here.
                return false;
        return false;

    Method #4

    A friend recently sent me this example right before publishing this. I have never seen this approach but never the less it is an example of how to implement this functionality.

    public class MyMainForm : System.Windows.Forms.Form, IMessageFilter
         const int WM_KEYDOWN = 0x100;
         const int WM_KEYUP = 0x101;
         public bool PreFilterMessage(ref Message m)
              Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
              if(m.Msg == WM_KEYDOWN && keyCode == Keys.Escape)
                   Console.WriteLine("Ignoring Escape...");
                   return true;
              return false;
         private void MyMainForm_Load(object sender, System.EventArgs e)
    Public Class MyMainForm
         Inherits System.Windows.Forms.Form
         Implements IMessageFilter
         Private WM_KEYDOWN As Integer = &H100
         Private WM_KEYUP As Integer = &H101
         Public Function PreFilterMessage(ByRef m As Message) As Boolean
              Dim keyCode As Keys = CType(CInt(m.WParam), Keys) And Keys.KeyCode
              If m.Msg = WM_KEYDOWN And keyCode = Keys.Escape Then
                   Console.WriteLine("Ignoring Escape...")
                   Return True
              End If
              Return False
         End Function 'PreFilterMessage
         Private Sub MyMainForm_Load(sender As Object, e As System.EventArgs)
         End Sub 'MyMainForm_Load
    End Class 'MyMainForm

    Please let me know if you find any issues in the sample code above.

  • How to clear cached contacts from Microsoft Outlook.

    A long time ago we needed a script to remove the cached contacts in Microsoft Outlook. After some research we found that these were stored in a NK2 file in the user profile directory. To run the script please close Outlook and create a new batch file (text file with the extension of .bat), or download the file below. Please not this will create a backup of the NK2 file so everything can be reverted.

    @ECHO off
    TITLE Clear the nickname automatic completion caches in Outlook
    ECHO Clearing the nickname automatic completion caches in OutLook...
    ECHO Created by Blake Niemyjski (
    CD %userprofile%\Application Data\Microsoft\Outlook
    RENAME *.NK2 *.NK2.BAK
    ECHO The operation has now completed.

    Download is attached to this post.

< Previous 1 2 3 4 5 Next > ... Last »;
Copyright © 2008 Windows Coding
Microsoft and Microsoft logo's are trademarks of Microsoft Corporation.