Entity Framework Code First – Decimal Precision Data Annotation Attribute

For anyone using Entity Framework’s Code First methodology, you will sooner or later run into the need to configure the precision and scale of a decimal field in your database. This can be easily done using the Fluent API, but if you prefer Data Annotations, you will find that there is no attribute to specify the precision and scale of a decimal. Below is a simple implementation of such an attribute:

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class Precision : Attribute
public byte precision { get; set; }
public byte scale { get; set; }

public Precision(byte precision, byte scale)
this.precision = precision;
this.scale = scale;

public static void ConfigureModelBuilder(DbModelBuilder modelBuilder)
modelBuilder.Properties().Where(x => x.GetCustomAttributes(false).OfType(Precision).Any()).Configure(c => c.HasPrecision(c.ClrPropertyInfo.GetCustomAttributes(false).OfType(Precision).First().precision, c.ClrPropertyInfo.GetCustomAttributes(false).OfType(Precision).First().scale));

Then in your OnModelCreating simply add the following:


And in your Model simply add the Precision attribute to any decimal properties.

[Precision(18, 9)]
public decimal? Latitude { get; set; }

[Precision(18, 9)]
public decimal? Longtitude { get; set; }


System.Windows.Markup.XamlParseException loading “Microsoft.VisualStudio.Shell.UI.Internal;component/StartPage.xaml”:

Every time I would start VS 2010 I was getting this error show up instead of the normal VS start page. Visual Studio would also crash whenever I tried to open a file.

After much googling I was unable to find a solution and so I gave up on VS 2010, and installed VS 2012 instead.

However after installing VS 2012, I got another error “Failed to create a ‘ImageSource’ from the text ‘..\Images\Medium.png'”.

Fixing this error was much easier… according to this page http://blogs.msdn.com/b/vsnetsetup/archive/2013/03/19/visual-studio-2012-ide-shows-failed-to-create-a-imagesource-from-the-text-images-medium-png-while-accessing-file-new-file-open-dialog-boxes.aspx uninstalling FastPictureViewer codec pack should do the trick.

And it did… now both VS 2010 & 2012 are both working fine!

LINQ2SQL – Transaction was deadlocked on lock resources with another process and has been chosen as the deadlock victim.

For a little while now I’ve had a problem with getting deadlocks on my LINQ2SQL operations, and so today I finally decided to dig a bit deeper.

The first useful thing I did, was use SQL Profiler to log some more details on the deadlocks. MSDN – Save Deadlock Graphs (SQL Server Profiler)

One of things I noticed when looking at the XDL files generated by the trace, was that the IsolationLevel was set to Serializable.

But I was pretty sure this wasn’t the default isolation level for LINQ2SQL and I wasn’t setting it in code anywhere.

So after using JetBrains dotPeek to look into the .NET CLR, I discovered two things:

  1. System.Data.LINQ.DataContext.SubmitChanges() uses ReadCommitted as it’s default isolation level.
  2. System.Transactions.TransactionScope defaults the isolation level of the transaction to Serializable.

So whenever I was performing an operation in a transaction using TransactionScope the isolation level was being set to Serializable.

For me ReadCommited is a nice balanced approach and Serializable a bit more than I need for my code.

So I decided to create a TransactionScopeBuilder class which simply generates a TransactionScope defaulted to the ReadCommitted isolation level.

new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted });

The result? For me, this has meant no more deadlocks, and far better performance!

Hopefully this can help others too!

SAP BusinessObjects Crystal Reports Download List

I’ve always struggled with managing different versions of the Crystal Reports redist, but it looks like finally SAP are getting it all together.

Here is a link to a list of all the .NET Crystal Report redist back to 2002. With download links 🙂


In case you are looking for a particular version (as I was), here is list of some of the newer dll versions included:

  • 10.2.3600.0
  • 10.5.3700.0
  • 11.0.3300.0
  • 11.5.3300.0
  • 12.0.1100.0
  • 12.0.2700.0
  • 13.0.2000.0

How to remove VsDebuggerCausalityData from a SOAP request

If you ever have to deal with a non-.NET (perhaps Java) based SOAP web service, you may come across the fact that .NET and Java, servers and clients, don’t always play well together.

A great application to help you in debugging these kinds of issues is “Charles”. You can download it from here http://www.charlesproxy.com/

The good thing about Charles, is you can even trace SSL encrypted SOAP requests, and then manually modify the SOAP XML and resend the request in order to narrow down what the server is not liking about your request.

Recently I had an issue where I was getting an “Security processing failed (actions mismatch)” response from the SOAP web service. After investigating with Charles, I found that the web service didn’t like the “VsDebuggerCasualityData” section that was being added to the request coming from the WCF client.

The solution was to run the Visual Studio Diagnostics WCF Registration tool, and disable debugger support for WCF.

For my installation of Visual Studio 2010, this tool is located in C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\

To uninstall, run the following vsdiag_regwcf.exe -u

You can also use the -i parameter to reinstall the debugger support for WCF, and you can use the -s parameter to check whether or not debugger support is enabled or not.

Posted in Errors. Tags: , , . 1 Comment »

Silverlight app not showing up in Firefox

I’ve just created a new Silverlight 4 application, and added it to an MVC site. I added a button to MainPage.xaml, and then built the projects.

However when I view my MVC site in Firefox, it simply shows a blank white screen! (IE and Chrome both work fine)

At first I thought this was related to the filename of my .xap, however I noticed that Firefox was loading the .xap from cache. Using firebug’s “Net” tab, I could see that it was only taking 100ms to load, and mentioned loading from cache.

So I cleared the cache (should of done this earlier), refreshed the page, and voila, it works!

Moral of the story is:

if at first you don’t succeed, clear your browser cache.

Hope this helps.

EDIT: Looks like this is a more general issue with Firefox not refreshing the cache at all, for at least Casini hosted silverlight apps. As a work-around simply add a dummy querystring parameter in the test page

<param name="source" value="ClientBin/MySilverlightApp.xap?firefoxHack"/>

If anyone has any other ideas please comment below.

ASP.NET MVC 3, IIS Express, VS2010 SP1 Beta & SQL CE 4 – They’ve all arrived!!!

Well… some how I missed the fact that Mircrosoft released a whole bunch of new things two weeks ago, January 13 2011, to be precise.

Included in their releases was ASP.NET MVC 3.

Here is the download link. http://www.microsoft.com/web/handlers/webpi.ashx?command=getinstaller&appid=MVC3

Hopefully soon I’ll be writing about some of the new features in ASP.NET MVC 3.

In the mean time have a look at Marcin Dobosz’s blog for the instructions on how to upgrade your project to ASP.NET MV3 using the upgrade utility, or Rick Schott’s blog for the manual way.

Stay tuned.