C# Diagnostic TimeClock class for debugging…

I like to clock certain operations, or group of operations to determine if a certain area of a function is taking a long time. It can be helpful to watch the progress of a function as well, with some useful eyeball metrics.

You can use the class below. Just create a blank class file and paste this in there.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CenterlineGroup.BPParts.BusinessLogic.Performance
public class TimeClock : IDisposable
private DateTime startTime = DateTime.Now;
private string operation = string.Empty;
public TimeClock(string Operation)
operation = Operation;
System.Diagnostics.Debug.WriteLine("Beginning operation: " + operation);

#region IDisposable Members

public void Dispose()
System.Diagnostics.Debug.WriteLine("Ending Operation: " + operation + ".It took " + (DateTime.Now - startTime).TotalMilliseconds + "ms to complete");


To use it, just create the following style code:

 using (var clock = new TimeClock("Shipment: Add Freight Cost To Order"))
                    Orders.AddFreightCostToOrder(request.OrderID, request.VendorID, request.ShippingAddressEntryID, request.ShippingCost);

Easy, eh? Simple, yet effective.

Entity Framework: The version of SQL Server in use does not support datatype ‘datetime2’

I development against a 2008 copy of SQL Server, which normally isn’t a problem, until….. I pushed out my latest code to the production system, which runs SQL 2005, and started smoke testing the system. As soon as I tried to write a record, i got the data type exception. Its painfully in the innerexception.

So, I think to myself, I am not doing anything amazing here. I am just trying to use the Entity Framework to write simple data. Well, apparently there is a tag in the store model saying what version of SQL you are targeting. Is there an easy property window for this? Nope. Open the XML.

If you change the 2008 out the server version you are targeting. 2005 or 2000 if your old, and voila. Up and running. I guess I need to upgrade the production servers to 2008. What a pain.

Right Click your EDMX file and open with XML Editor. Change ProviderManifestToken=2008 to ProviderManifestToken=2005

Then change the following:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
 <!-- EF Runtime content -->
 <!-- SSDL content -->
 <Schema Namespace="MyDataModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005"
 <EntityContainer Name="MyDBModelStoreContainer">

DataBinding: ‘Telerik.Web.UI.GridInsertionObject’ does not contain a property with the name ‘UserName’.

I use the Telerik controls for a lot of my web work. They save a lot of time but every once in a while they really irritate the hell out of me. A few hours down the rabbit hole and I find that when binding to an EntityDataSource on a RadGrid when trying to insert an item on an empty list. i.e. no records yet, you get the title error.

So, what is the work around? A dummy row on an empty insert. Awesome huh. Well, at least it works.

  protected void dgAuthorizedUsers_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        if (e.CommandName == Telerik.Web.UI.RadGrid.InitInsertCommandName )
            e.Canceled = true;
            var newVals = new System.Collections.Specialized.ListDictionary();
            newVals["UserName"] = string.Empty;

Make sure to add all the different fields you use. So much for declarative programming eh?

Visual Studio 2010 release date announced – .NET framework 4.0

I found a link to the Register that mentions that Visual Studio 2010 will be released on March 22nd of 2010. The beta is currently available for download from Microsoft

I can’t wait for the new Entity Framework with 4.0 ; they fix so many annoyances I have with the current version.

It appears that they will be changing the packages they sell now. I know they are transitioning us folks with Team Developer licenses up to the Ultimate license, which is really cool. They are also giving us full TFS server licenses gratis as well.

Quote from the Register’s site:

Microsoft will chop nine Visual Studio SKUs down to four, with the focus on ALM. Microsoft does not seem to be tampering with the Express editions, which add another five SKUs.

Visual Studio Development Edition, Database Edition, Architect Edition and Test Edition will go. These will give way to Visual Studio 2010 Professional priced $799 and no MSDN subscription option, Professional priced $1,199 for a new MSDN subscription, Premium priced $5,469 for a new MSDN subscription, and the new completely Ultimate Visual Studio SKU that will be priced $11,924 for a new MSDN subscription.

Entity framework gives you an error when you add foreign key relationships after you already modeled..

The Entity Framework has a lot of nice features in it for mapping relationships. The bugger is its incessant need for the actual foreign key relationships on the database. Unless of course you like editing XML and never want to use the model wizard again.

So you model your database without the foreign keys, deciding “Ill add those later”. You add them and then run the update model wizard. Cool, the relationships appear but the model doesn’t validate.

Error 20 Error 3007: Problem in Mapping Fragments starting at lines 1586, 2100: Non-Primary-Key column(s) [UserID] are being mapped in both fragments to different conceptual side properties - data inconsistency is possible because the corresponding conceptual side properties can be independently modified.
What to do?

It’s actually easy. Just delete the old keys from the entity. ex. You added the Users table relationship. Well, delete the UserID off the entity.

All done.

Visual C++, Precompiled Headers and Windows 7

I upgraded to Windows 7 and I really am enjoying the new interface….but….. I went to compile my ActiveX toolset projects that are all written in C++ and I started getting  precompiled header errors.

So I rebuilt and rebuilt and still got the error:

Error    1    fatal error C1859: ‘.Release/HTTP Wizard.pch’ unexpected precompiled header error, simply rerunning the compiler might fix this problem    d:SSIC++v3HTTP Wizard v3HTTPAccess.cpp    5    HTTP Wizard

So I rebuilt and rebuilt. No avail. I turned off Precompiled headers and then everything worked fine. What a pain.

It turned out the reason is due to the virtual tables being rebased by Windows 7 for security which totally screws up the precompiled header logic, which requires the headers to be in the same memory locations.

Apparently the development team at Microsoft knows about the issue and will eventually fix it. So, lets hope that service pack comes out soon.

I guess I am lucky my build machine is really beefy, but for active development having the precompiled header is nice.

So, go have a Margarita and the  compiler errors won’t bother you as much…..