LINQ to SQL Unspecified Error and missing designer file

I’ve been doing battle with the LINQ to SQL designer for a while now so I was surprised to be caught out by this, frankly, unbelievable issue. Putting together some example code for my next post, I had a .dbml file with around 4 classes, and suddenly the designer began throwing up a very unhelpful ‘Unspecified Error’ every time I tried to make any changes.

Error message

Eventually I realised that every time I saved the diagram, the .designer.cs file was being deleted!

Missing file

A bit of googling turned up the solution here, I had added some code to the auto-generated partial class file (Data.cs), and foolishly didn’t realise that any ‘using’ statements in that file have to go inside the namespace declaration!

Wrong:

namespace GraphVizDebugging
{
  using System;

  partial class Predicate

Right:

namespace GraphVizDebugging
{
  using System;

  partial class Predicate
29 January 2010 by Jon Merrifield