Specify Linq To SQL ConnectionString explicitly

When modifying Linq to  Sql data model in Visual Studio 2010,  it re-assigns ConnectionString that is available on developer’s machine.
Because the name can be different on different machines, Designer often replace it with something like ConnectionString1, which causes errors during deployment.
It requires developers to ensure that ConnectionString stays unchanged.
 
More reliable way is to use context constructor with explicit ConnectionString name instead of parameterless default constructor

GOOD:
  var ctx = new MyModelDataContext(Settings.Default.ConnectionString);
Not good:
         var ctx = new MyModelDataContext();

Do not expose enum in WCF response

We had a backward compatibility problem in WCF client, when in Service application a new value was added to one of enums. We discussed different ways to avoid this backward compatibility issues, and I found recommendation do not expose enum in wcf response in http://stackoverflow.com/a/788281/52277.

It is still required to create new versions of our service interfaces to replace each enum fields with string field, that expects only documented values, and describe, what should be default behavior, if field has an unexpected value.

 

As a workaround for backward- compatibility of enums, they can be declared as [DataContract] and only old values set as [DataMember] , but left new values without the attribute until the new MAJOR release.Members that are not marked are not serialized.  See Enumeration Types in Data Contracts.

Visual Studio 10 crashed when tried to open one of solutions

Visual Studio 10 crashed when I tried to open  one of my solutions. Closing Visual Studio and rebooting the machine didn’t help.
The error message that was logged(see below), didn’t give any useful ideas.
Finally It was fixed after I’ve deleted MySolution.suo file, which was quite big, and also Resharper folders.

Log Name:      Application
Source:        Application Error
Event ID:      1000
Task Category: (100)
Level:         Error
Keywords:      Classic
User:          N/A
Description:
Faulting application name: devenv.exe, version: 10.0.40219.1, time stamp: 0x4d5f2a73
Faulting module name: msenv.dll, version: 10.0.40219.1, time stamp: 0x4d5f2d48
Exception code: 0xc0000005
Fault offset: 0x00355770
Faulting process id: 0x1dc0
Faulting application start time: 0x01cd1836888599f4
Faulting application path: C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEdevenv.exe
Faulting module path: c:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEmsenv.dll
Report Id: 9924b2f9-844e-11e1-bc19-782bcba513ea
Event Xml:
<Event xmlns=”http://schemas.microsoft.com/win/2004/08/events/event”>
 <System>
   <Provider Name=”Application Error” />
   <EventID Qualifiers=”0″>1000</EventID>
   <Level>2</Level>
   <Task>100</Task>
   <Keywords>0x80000000000000</Keywords>
   <TimeCreated SystemTime=”2012-04-12T03:21:31.000000000Z” />
   <EventRecordID>401998</EventRecordID>
   <Channel>Application</Channel>
   <Security />
 </System>
 <EventData>
   <Data>devenv.exe</Data>
   <Data>10.0.40219.1</Data>
   <Data>4d5f2a73</Data>
   <Data>msenv.dll</Data>
   <Data>10.0.40219.1</Data>
   <Data>4d5f2d48</Data>
   <Data>c0000005</Data>
   <Data>00355770</Data>
   <Data>1dc0</Data>
   <Data>01cd1836888599f4</Data>
   <Data>C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEdevenv.exe</Data>
   <Data>c:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEmsenv.dll</Data>
   <Data>9924b2f9-844e-11e1-bc19-782bcba513ea</Data>
 </EventData>
</Event>v

Translate jQuery UI Datepicker format to .Net Date format

I needed to use the same date format in client jQuery UI Datepicker and server ASP.NET code. The actual format can be different for different localization cultures.

I decided to translate Datepicker format to .Net Date format similar as it was asked to do opposite operation in http://stackoverflow.com/questions/8531247/jquery-datepickers-dateformat-how-to-integrate-with-net-current-culture-date

Note that replace command need to replace whole words and order of calls is important

Function that does opposite operation (translate  .Net Date format toDatepicker format) is described in
http://www.codeproject.com/Articles/62031/JQueryUI-Datepicker-in-ASP-NET-MVC


/// <summary>
/// Uses regex ‘b’ as suggested in //http://stackoverflow.com/questions/6143642/way-to-have-string-replace-only-hit-whole-words
/// </summary>
/// <param name=”original”></param>
/// <param name=”wordToFind”></param>
/// <param name=”replacement”></param>
/// <param name=”regexOptions”></param>
/// <returns></returns>
static public string ReplaceWholeWord(this string original, string wordToFind, string replacement,
RegexOptions regexOptions = RegexOptions.None)
{

string pattern =
String.Format(@”b{0}b”, wordToFind);
string ret=
Regex.Replace(original, pattern, replacement, regexOptions);
return ret;
}

/// <summary>
/// E.g “DD, d MM, yy” to ,”dddd, d MMMM, yyyy”
/// </summary>
/// <param name=”datePickerFormat”></param>
/// <returns></returns>
/// <remarks>
/// Idea to replace from http://stackoverflow.com/questions/8531247/jquery-datepickers-dateformat-how-to-integrate-with-net-current-culture-date
///From http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate to http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
///Format a date into a string value with a specified format.
///d – day of month (no leading zero) —.Net the same
///dd – day of month (two digit) —.Net the same
///D – day name short —.Net “ddd”
///DD – day name long —.Net “dddd”
///m – month of year (no leading zero) —.Net “M”
///mm – month of year (two digit) —.Net “MM”
///M – month name short —.Net “MMM”
///MM – month name long —.Net “MMMM”
///y – year (two digit) —.Net “yy”
///yy – year (four digit) —.Net “yyyy”
/// </remarks>
public static string JQueryDatePickerFormatToDotNetDateFormat(string datePickerFormat)
{

string sRet = datePickerFormat.ReplaceWholeWord(
“DD”, “dddd”).ReplaceWholeWord(“D”, “ddd”);
sRet = sRet.ReplaceWholeWord(
“M”, “MMM”).ReplaceWholeWord(“MM”, “MMMM”).ReplaceWholeWord(“m”, “M”).ReplaceWholeWord(“mm”, “MM”);//order is important
sRet = sRet.ReplaceWholeWord(
“yy”, “yyyy”).ReplaceWholeWord(“y”, “yy”);//order is important
return sRet;
}