A little note to the new developer that is just getting into writing Extension Methods in .NET 3.5.  Your extensions will not show up until you compile your static classes.  This should be obvious to most but the Visual Studio 2008 IDE does not precompile the extension methods while you are coding.  It does this for all your other code.. e.g. if you are writing a class and then write a class that consumes it your class is immediately available via intellisense. 

Extension methods need to be compiled before they show up in your Intellisense list.  So do not freak out or think the magic is gone.

I have a fresh install of Vista Business x64 with a clean install of Visual Studio 2008 SP1.  I updated my Telerik R.A.D. Controls Winforms from an older 2007 version to 2008 Q2 SP1.  After which (and I do not fault Telerik for this as it is a VS2008 issue not a Telerik issue) my Visual Studio 2008 SP1 started crashing.  My event log had errors such as this:

.NET Runtime version 2.0.50727.3053 – Fatal Execution Engine Error (000007FEF957203F)

The remote debugger is unable to communicate with Visual Studio, and must abort the remote debugging session. Please restart debugging.

Faulting application devenv.exe, version 9.0.30729.1, time stamp 0x488f2b50, faulting module unknown, version, time stamp 0x00000000, exception code 0xc0000005, fault offset 0x330001ca, process id 0x136c, application start time 0x01c92d91f586f1eb.

.NET Runtime version 2.0.50727.3053 – Fatal Execution Engine Error (6EC00F92)

I solved the problem by doing the following:

Close Visual Studio if it is open (in fact it is a good idea to stop all programs that are running).

Delete all files in: (skip locked files)


C:\Users\<UserDir>\Local Settings\Temp

if you are still on Windows XP:

C:\Documents and Settings\Local Settings\Temp

and most importantly

C:\Users\<UserDir>\Local Settings\Microsoft\VisualStudio

if you are still on Windows XP:

C:\Documents and Settings\Local Settings\Microsoft\VisualStudio

Restart Visual Studio 2008 and you should be good to go!

So in short:  reboot.


This is actually kind of funny.  The fix for Vista was only published a week ago.  There is apparently a memory leak of some sort that causes Windows to stop loading large executables.

Here is the funny part of the KB article:

This update improves the reliability of Windows Vista SP1-based computers that experience issues in which large applications cannot run after the computer is turned on for extended periods of time. For example, when you try to start Excel 2007 after the computer is turned on for extended periods of time, a user may receive an error message that resembles the following:

EXCEL.EXE is not a valid Win32 application

Sorry Microsoft.. I normally have your back but this is a monster of a quality miss.

So I have not embeded many reports in ASP.NET web sites to date so I am a little late on this news.  I finally added a report to a ASP.NET 3.5 web site and used the Report Viewer control.  After deploying the control I received this message:

Could not load file or assembly ‘Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.

I read a few newsgroup postings about this which gave some hard to swallow advice.  I figured there must be a better way.  There is.

All you need to do is install the Redistributable package on the target web server for your version of report viewer.

For VS2008 use this one:

For VS2005 use this:

Installing these and restarting IIS did the trick!

EDIT: Related to this is my other blog here: http://davidsandor.com/blogs/tipsandtricks/archive/2008/07/16/solved-the-base-class-includes-the-field-reportviewer1-but-its-type-microsoft-reporting-webforms-reportviewer-is-not-compatible-with-the-type-of-control-microsoft-reporting-webforms-reportviewer.aspx There are apparently issues when upgrading a Visual Studio 2005 project with a report viewer control to a Visual Studio 2008 project.  You must hack your .SLN or .CSPROJ files to fix the annoying bug.

So I have a situation where I need to concatenate text onto the end of a GUID in order to do a SQL Query.  There is a field in the database I am working with that uses a GUID and a word as a key.  Ignore that nastiness for a moment.

So if you do the following:


@divrefid uniqueidentifier

set @divrefid = (SELECT DivisionRefID from [ORDER] where solomonorderid=@solomonorderid)


* from displaystring where [key]= + @divrefid + ‘UserDefinedField1’

This attempts to use implicit conversion to convert the uniqueidentifier into a varchar field and append a string to the text.  This results in the following error:

The data types varchar and uniqueidentifier are incompatible in the add operator. 

Attempt to cast the guid into a varchar or convert the guid into a varchar and you get this error:

Insufficient result space to convert uniqueidentifier value to char.

So the solution to this mess is to allow a select statement to perform the conversion implicitly like this:


@divrefid varchar(150)

undefined @divrefid = (SELECT DivisionRefID from [ORDER] where solomonorderid)

Now the conversion is done and the GUID is now a varchar like any other.

Originally published on MSDN Academic Alliance:  http://www.academicresourcecenter.net/curriculum/pfv.aspx?ID=7083
Since .NET 2.0 generics have been available to .NET developers.  I have worked with developers that have been excited to use the new features of Generics but have been hindered by the concept of predicates.  I hope to expose the simplicity and elegance of Predicates so that they are better understood and added as a valuable tool in your developer tool belt.


For simplicity I will pose the most common questions I have received from developers and show how these problems can be solved with a Predicate.

I have a List<> of strings and I just want to see if a particular string already exists in the list.  I used to be able to simply pass in an object to the Exists() method of an array list to check its existence, now it asks for a predicate.

One option is to create a class that inherits from List<string> and implements an override for the Exists() method that takes a string.  Here I will show you how to do this with a predicate.

The FindStringPredicate class will allow you to specify what string to find and how to find it.  Now you are probably looking at this right about now and saying, “How is this better than simply passing in a string to an ArrayList.Exists() method?”  Well in this case it is a good deal of overhead, BUT when you are writing large programs using lots of modeled classes you are not dealing with a lot of primitive types but rather you are dealing with complex objects.  The good part is that you can create a whole library of primitive type predicate objects that you can use in any project.

With that said, you now need to actually find a string in the string list. 

The output of this code is the following:

Does Avicenna exist? True

So what is happening here?  Well we added a few names to a generic List<> of type string.  We then created an instance of the FindStringPredicate class and passed in the name we were looking for and also told the FindStringPredicate class to do a case sensitive comparison.  Behind the scenes the generic List<>.Exists() method called the FindStringPredicate.Find() method for each item in the list.  The logic in the Find() method then compared the item in the list to the value of the string set in the FindStringPredicate class.

What if I want a quick and dirty way of checking if a string already exists, is there an easier way?

Yes!  If your logic is simple and you do not plan on reusing it elsewhere you can create an anonymous delegate to perform your test.  This sounds complicated but basically all you are doing is defining a piece of code to have the Exists() method call for each item in the list.  This is how you do it:

In this code block you can see that instead of passing a target method to the constructor of the Predicate<> class we are simply passing in an anonymous delegate.  This anonymous delegate consists of an argument of string lineItem.  This is because the Exists() method calls your predicate for each item in the list.  When it calls the predicate it passes in an object of the type you specified in the new Predicate<string> section of code.  So in this case the Exists code passes in strings as the argument to the predicate’s target method.  Now enclosed in the parenthesis you have a line of code that returns a Boolean value.  This block of code can be as large or small as needed.

On to the Real World usage of Predicates

While the first example is a little drawn out it is really not addressing the true value of Predicates.  The real value comes in to play when you have complex classes in a generic list.  Because there are generic predicates you can specify the predicate’s target argument type (aka the type of the object that exists in the generic list.)

In this example we will have a generic list of Car objects.  We want to find all the cars that have green paint.

First we will define our car class as follows:

Now we will define a class that will allow us to query a generic list of Car classes.

This class takes a Car object as a parameter and sets a public field to the value of the Car class.  The idea here is that we can use a simple car object instance to define our query.  You could have also taken in an argument of type CarColor but we want to use this CarPredicate class for more than just color based queries.  There must be a dozen ways you can do this but I think this approach sets you up for understanding LINQ in the near future.

So with this class we have defined a method FindByColor which will be used to compare a car object against the CarQuery instance field.  If the color matches it returns true otherwise it returns false.

Now we will use our CarPredicate class to search for all the green cars in a generic list of Car objects:

The result of this code is the following:

Car Make: Acura, Model: Integra, Color: Green
Car Make: Jeep, Model: Liberty, Color: Green

The code builds a list of Car objects with various colors, makes and models.  Next we create an instance of the CarPredicate class and pass in a partially populated car object.  Next we call the FindAll() method of the generic list and pass in the FindByColor method as the target of the predicate.  Notice that we are creating an instance of a generic predicate with the code: new Predicate<Car>. This means that when the target method, in this case FindByColor, is called an argument of type Car will be passed to the FindByColor method.

Lets extend the CarPredicate class a bit to allow you to query for more than just color.

Add a new color of “Any” to the CarColor enum.

Now we have a Find method in the CarPredicate class that will allow us to search for cars by name, make or model simply by specifying any combination of properties of the CarQuery class. 

We can use this new method in the following manner:

This code segment finds the Jeep in the list and outputs the values of the class.

I hope now that you see the value of these new Predicate based methods of the Generic list.  Not only do you have the power of defining your search code and reusing the search code anywhere you use collections of your objects but you have the power of strongly typed lists. 

This should not be this hard.  I found examples everywhere.  All failed until I found the post here: http://forums.asp.net/p/1015907/1365445.aspx

I adapted that code slightly to make it a bit more effecient, the result is below.

Yeah so I am a few days behind.. I am starting a new job so sue me.  (Lawyers Disclaimer:  Authors notes in the previous sentance are not to be construde as an invitation for a legal law suit.  The said author was merely using a colloquialism.)

The new library will also contain a Configuration Editor that bakes into Visual Studio and a Validation Application block with a bunch of pre-made validators.  This is a really cool Application Block because it centralizes the validation of data going into and out of your business objects.

Check it out here: http://www.codeplex.com/entlib