The custom tool ‘MSLinqToSQLGenerator’ failed. Unspecified error

I kept getting this error “The custom tool ‘MSLinqToSQLGenerator’ failed.  Unspecified error.   For me, this was caused when I was using partial classes and had several using statements at the top of the file:

using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel;
using System;

{namespace}

{code}

To get around this, I removed the using namespaces and ran the custom build tool, then readded the using statements which resolved my issue.   This issue apparently is in SP1 VS2008!

References:

http://blog.unidev.com/index.php/2008/09/02/the-custom-tool-mslinqtosqlgenerator-failed-unspecified-error/

Match Whole Words Regular Expressions

Example:

Dim regExp As New Regex(String.Format(“\b{0}\b”, keyword), RegexOptions.IgnoreCase)

This is the same as doing the following:

1
2
3
note.note_content.StartsWith(InputKeyword & " ") OR _
note.note_content.EndsWith(" " & InputKeyword) OR _
note.note_content.Contains(" " & InputKeyword & " ")

References:

http://answers.oreilly.com/topic/217-how-to-match-whole-words-with-a-regular-expression/

http://stackoverflow.com/questions/810078/search-for-whole-word-with-linq-to-sql

Unable to cast object of type ‘ Issue

I came across this error:

System.InvalidCastException: Unable to cast object of type ‘<TakeIterator>d__3a`1[Class]‘ to type ‘System.Collections.Generic.List`1[Class]‘.

This occured when trying to use the Take extension (list.Take(n)) from a generic list of objects.   The problem is when you use the Take extension, it returns a new sequence (

1
IEnumerable).

I got around this issue by using:

list.Take(8).ToList() which gets the new sequence and then converts back to the generic list.

References:

http://stackoverflow.com/questions/1431782/unable-to-cast-object

Interview Questions Part 1

Over the past month, I have been interviewed by several companies and I thought I would share some of my experiences.   Here are some of the questions I was asked (Technical):

  • What is the difference between a reference type and a value type?
  • What is the difference between a stack and a heap?
  • What is the GAC?
  • Is a String a reference type or value type?
  • Can you inherit a class from two different classes?
  • What is a interface? What is the difference between a interface and a class?

Some other non-technical factors to consider..out of the four companies I saw, all of them use SCRUM.

Modify a Word 2007 Open XML document via C#

Interesting problem that I came across here…A client requested that their system was to have the ability to load in a Word 2007 Document, perform some text manipulation routines and save the document back to the server.

Firstly, you can rename a docx document to docx.zip and you can extract all of the files in the zip file that build the foundation of the Open XML document.   Not bad!

Here is the code that I used to open a Word 2007 document, do some manipulation and save the file.

using (WordprocessingDocument wdDoc = WordprocessingDocument.Open(newPath, true))
{

string docText;
using (var sr = new StreamReader(wdDoc.MainDocumentPart.GetStream()))
{
docText = sr.ReadToEnd();
}

docText = RegExpReplace(“{REPLACETEXTHERE}”, docText, “With this value”);
using (var sw = new StreamWriter(wdDoc.MainDocumentPart.GetStream(FileMode.Create)))
{
sw.Write(docText);
}

}

The WordprocessingDocument classes are part of the Open XML Format 1.0 SDK available from Microsoft.

This beats having to do the old way of importing Office API Dlls via COM to load and write word documents!

References:

http://msdn.microsoft.com/en-us/library/documentformat.openxml.packaging.wordprocessingdocument.aspx

A CMS that integrates into ASP.NET MVC

Here is a open source CMS called N2 that provides a CMS framework to build web applications on using the ASP.NET MVC Model.   Its a very basic CMS, but it provides all the core functionality including Pages, Articles and a .NET Permissions Model (it also has some add ons and allows developers to contribute their own add ons).   They have lots of documentation and useful examples on how to work the CMS with MVC.   Very cool stuff!

References:

http://n2cms.com