30 April, 2010

Download and Share Visual Studio Color Schemes

Download and Share Visual Studio Color Schemes: "
As developers we often spend a large part of our day staring at code within Visual Studio. If you are like me, after awhile the default VS text color scheme starts to get a little boring.
The good news is that Visual Studio allows you to completely customize the editor background and text colors to whatever you want – allowing you to tweak them to create the experience that is “just right” for your eyes and personality. You can then optionally export/import your color scheme preferences to an XML file via the Tools >>Import and Export Settings menu command.

New website that makes it easy to download and share VS color schemes

Luke Sampson launched the http://studiostyles.info/ site a week ago (built using ASP.NET MVC 2, ASP.NET 4 and VS 2010).
Studiostyles.info enables you to easily browse and download Visual Studio color schemes that others have already created. The color schemes work for both VS 2008 and VS 2010 (all versions – including the free VS express editions):
image
Color schemes are sorted by popularity and voting (you can vote on whether you find each “hot or not”).
You can click any of the schemes to see screen-shots of it in use for common coding scenarios. You can then download the color settings for either VS 2010 or VS 2008:
image
You can also optionally upload color schemes of your own if you have a good one you want to share with others.
If you haven’t visited it yet – check it out: http://studiostyles.info/ And thank you Luke Sampson for building it!

26 April, 2010

DateTime Format DateTime.ToString() Patterns

All the patterns:



0

MM/dd/yyyy

08/22/2006

1

dddd, dd MMMM yyyy

Tuesday, 22 August 2006

2

dddd, dd MMMM yyyy

HH:mm Tuesday, 22 August 2006 06:30

3

dddd, dd MMMM yyyy

hh:mm tt Tuesday, 22 August 2006 06:30 AM

4

dddd, dd MMMM yyyy

H:mm Tuesday, 22 August 2006 6:30

5

dddd, dd MMMM yyyy

h:mm tt Tuesday, 22 August 2006 6:30 AM

6

dddd, dd MMMM yyyy HH:mm:ss

Tuesday, 22 August 2006 06:30:07

7

MM/dd/yyyy HH:mm

08/22/2006 06:30

8

MM/dd/yyyy hh:mm tt

08/22/2006 06:30 AM

9

MM/dd/yyyy H:mm

08/22/2006 6:30

10

MM/dd/yyyy h:mm tt

08/22/2006 6:30 AM

10

MM/dd/yyyy h:mm tt

08/22/2006 6:30 AM

10

MM/dd/yyyy h:mm tt

08/22/2006 6:30 AM

11

MM/dd/yyyy HH:mm:ss

08/22/2006 06:30:07

12

MMMM dd

August 22

13

MMMM dd

August 22

14

yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK

2006-08-22T06:30:07.7199222-04:00

15

yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK

2006-08-22T06:30:07.7199222-04:00

16

ddd, dd MMM yyyy HH':'mm':'ss 'GMT'

Tue, 22 Aug 2006 06:30:07 GMT

17

ddd, dd MMM yyyy HH':'mm':'ss 'GMT'

Tue, 22 Aug 2006 06:30:07 GMT

18

yyyy'-'MM'-'dd'T'HH':'mm':'ss

2006-08-22T06:30:07

19

HH:mm

06:30

20

hh:mm tt

06:30 AM

21

H:mm

6:30

22

h:mm tt

6:30 AM

23

HH:mm:ss

06:30:07

24

yyyy'-'MM'-'dd HH':'mm':'ss'Z'

2006-08-22 06:30:07Z

25

dddd, dd MMMM yyyy HH:mm:ss

Tuesday, 22 August 2006 06:30:07

26

yyyy MMMM

2006 August

27

yyyy MMMM

2006 August

The patterns for DateTime.ToString ( 'd' ) :



0

MM/dd/yyyy

08/22/2006

The patterns for DateTime.ToString ( 'D' ) :



0

dddd, dd MMMM yyyy

Tuesday, 22 August 2006

The patterns for DateTime.ToString ( 'f' ) :



0

dddd, dd MMMM yyyy HH:mm

Tuesday, 22 August 2006 06:30

1

dddd, dd MMMM yyyy hh:mm

tt Tuesday, 22 August 2006 06:30 AM

2

dddd, dd MMMM yyyy H:mm

Tuesday, 22 August 2006 6:30

3

dddd, dd MMMM yyyy h:mm

tt Tuesday, 22 August 2006 6:30 AM

The patterns for DateTime.ToString ( 'F' ) :



0

dddd, dd MMMM yyyy HH:mm:ss

Tuesday, 22 August 2006 06:30:07

The patterns for DateTime.ToString ( 'g' ) :



0

MM/dd/yyyy HH:mm

08/22/2006 06:30

1

MM/dd/yyyy hh:mm

tt 08/22/2006 06:30 AM

2

MM/dd/yyyy H:mm

08/22/2006 6:30

3

MM/dd/yyyy h:mm tt

08/22/2006 6:30 AM

The patterns for DateTime.ToString ( 'G' ) :



0

MM/dd/yyyy HH:mm:ss

08/22/2006 06:30:07

The patterns for DateTime.ToString ( 'm' ) :



0

MMMM dd

August 22

The patterns for DateTime.ToString ( 'r' ) :



0

ddd, dd MMM yyyy HH':'mm':'ss 'GMT'

Tue, 22 Aug 2006 06:30:07 GMT

The patterns for DateTime.ToString ( 's' ) :



0

yyyy'-'MM'-'dd'T'HH':'mm':'ss

2006-08-22T06:30:07

The patterns for DateTime.ToString ( 'u' ) :



0

yyyy'-'MM'-'dd HH':'mm':'ss'Z'

2006-08-22 06:30:07Z

The patterns for DateTime.ToString ( 'U' ) :



0

dddd, dd MMMM yyyy HH:mm:ss

Tuesday, 22 August 2006 06:30:07

The patterns for DateTime.ToString ( 'y' ) :



0

yyyy MMMM 2006 August

Building a custom DateTime.ToString Patterns

The following details the meaning of each pattern character. Not the K and z character.


d

Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero

dd

Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero

ddd

Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc)

dddd

Represents the full name of the day of the week (Monday, Tuesday etc)

h

12-hour clock hour (e.g. 7)

hh

12-hour clock, with a leading 0 (e.g. 07)

H

24-hour clock hour (e.g. 19)

HH

24-hour clock hour, with a leading 0 (e.g. 19)

m

Minutes

mm

Minutes with a leading zero

M

Month number

MM

Month number with leading zero

MMM

Abbreviated Month Name (e.g. Dec)

MMMM

Full month name (e.g. December)

s

Seconds

ss

Seconds with leading zero

t

Abbreviated AM / PM (e.g. A or P)

tt

AM / PM (e.g. AM or PM

y

Year, no leading zero (e.g. 2001 would be 1)

yy

Year, leadin zero (e.g. 2001 would be 01)

yyy

Year, (e.g. 2001 would be 2001)

yyyy

Year, (e.g. 2001 would be 2001)

K

Represents the time zone information of a date and time value (e.g. +05:00)

z

With DateTime values, represents the signed offset of the local operating system's time zone from Coordinated Universal Time (UTC), measured in hours. (e.g. +6)

zz

As z but with leadin zero (e.g. +06)

zzz

With DateTime values, represents the signed offset of the local operating system's time zone from UTC, measured in hours and minutes. (e.g. +06:00)

f

Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value.

ff

Represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value.

fff

Represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.

ffff

Represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value. While it is possible to display the ten thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.

fffff

Represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value. While it is possible to display the hundred thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.

ffffff

Represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a second in a date and time value. While it is possible to display the millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.

fffffff

Represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value. While it is possible to display the ten millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.

F

Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. Nothing is displayed if the digit is zero.

:

Represents the time separator defined in the current DateTimeFormatInfo..::.TimeSeparator property. This separator is used to differentiate hours, minutes, and seconds.

/

Represents the date separator defined in the current DateTimeFormatInfo..::.DateSeparator property. This separator is used to differentiate years, months, and days.

"

Represents a quoted string (quotation mark). Displays the literal value of any string between two quotation marks ("). Your application should precede each quotation mark with an escape character (\).

'

Represents a quoted string (apostrophe). Displays the literal value of any string between two apostrophe (') characters.

%c

Represents the result associated with a c custom format specifier, when the custom date and time format string consists solely of that custom format specifier. That is, to use the d, f, F, h, m, s, t, y, z, H, or M custom format specifier by itself, the application should specify %d, %f, %F, %h, %m, %s, %t, %y, %z, %H, or %M. For more information about using a single format specifier, see Using Single Custom Format Specifiers.
\c Represents the escape character, and displays the character "c" as a literal when
that character is preceded by the escape character (\). To insert the backslash character itself in
the result string, the application should use two escape characters ("\\").
Any other character copies any other character to the result string, without affecting formatting. ||

Get Cheet Sheets for Format

22 April, 2010

Visual Basic 2010 Language Enhancements

Introduction

Earlier this month Microsoft released Visual Studio 2010, the .NET Framework 4.0 (which includes ASP.NET 4.0), and new versions of their core programming languages: C# 4.0 and Visual Basic 10 (also referred to as Visual Basic 2010). Previously, the C# and Visual Basic programming languages were managed by two separate teams within Microsoft, which helps explain why features found in one language was not necessarily found in the other. For example, C# 3.0 introduced collection initializers, which enable developers to define the contents of a collection when declaring it; however, Visual Basic 9 did not support collection initializers. Conversely, Visual Basic has long supported optional parameters in methods, whereas C# did not.

Recently, Microsoft merged the Visual Basic and C# teams to help ensure that C# and Visual Basic grow together. As explained by Microsoft program manager Jonathan Aneja, "The intent is to make the languages advance together. When major functionality is introduced in one language, it should appear in the other as well. ... [T]hat any task you can do in one language should be as simple in the other." To this end, with version 4.0 C# now supports optional parameters and named arguments, two features that have long been part of Visual Basic's vernacular. And, likewise, Visual Basic has been updated to include a number of C# features that it was previously missing.

This article explores some of these new features that were added to Visual Basic 2010. Read on to learn more! 

Implicit Line Continuation (It's About Time!)

All programming languages use some character to denote the end of a statement. C-flavored languages (like C#) use the semicolon to mark the end of a statement, whereas the Basic programming language has long used the carriage return. One downside of using the carriage return as the statement delimiter is that it prohibits developers from having a single statement span multiple lines.

Consider the following function declaration:


Public Function ChangePassword(ByVal Username As String, ByVal OldPassword As String, ByVal NewPassword As String) As Boolean

   ...

End Function

We could improve the readability of the function declaration by having each input parameter on its own line. But doing so would confuse the compiler, as it presumes that a carriage return denotes the end of a statement. In the past, Visual Basic allowed for a single statement to be spread over multiple lines by using the line continuation character, an underscore (_). Using the line continuation character we could rewrite the above function declaration to span multiple lines like so:


Public Function ChangePassword(ByVal Username As String, _

                               ByVal OldPassword As String, _

                               ByVal NewPassword As String) As Boolean

   ...

End Function

Note the underscore after the Username and OldPassword input parameters.

Visual Basic 2010 still supports the use of the underscore as an explicit line continuation character, but it also supports implicit line continuation. Thanks to implicit line continuation in VB 2010, you can now continue lines of code on a new line without having to use the underscore character. For example, the above function declaration could be rewritten to omit the underscores, as the below screen shot illustrates.


Look ma, no underscores!


In short, the Visual Basic 2010 compiler allows you to omit the underscore when continuing a statement on the next consecutive line. It's natural to wonder how VB can distinguish between a carriage return that signifies a line continuation and one that signifies the end of a statement. There are certain syntax elements that cannot be used to end a statement and if VB notes a carriage return after one of these it can safely assume that the carriage return is meant as a line continuation character and not as the end of the statement. The following table lists the some of the syntax elements that, when followed by a carriage return, is treated as an implicit line continuation character by the compiler.


After a comma

After an open parenthesis or before a closing parenthesis

After an open curly brace or before a closing curly brace

After an open embedded expression (<%=) or before the close of an embedded expression (%>) within an XML literal

After the concatenation operator (&)

After assignment operators (=, &=, +=, ...)

After binary operators (+, -, And, Or, ...) within an expression

After the Is and IsNot operators

After a member qualifier character (.) and before the member name

For a complete list of the syntax elements as well as for examples of the above syntax elements in use, refer to the Statements in Visual Basic documentation's "Implicit Line Continuation" section.

Auto-Implemented Properties

When creating a class it's quite common to have one or more properties that don't include any logic in their getters or setters; instead, the property serves merely as a mechanism to expose a member variable. Most every Visual Basic developer has written code that looks like the following at some point or another:


Public Class Product

   Private _ProductName As String

   Private _UnitCost As Decimal

   

   Public Property ProductName As String

      Get

         Return _ProductName

      End Get

      Set (ByVal value As String)

         _ProductName = value

      End Set

   End Property



   Public Property ProductName As Decimal

      Get

         Return _UnitCost

      End Get

      Set (ByVal value As Decimal)

         _UnitCost = value

      End Set

   End Property

End Class

Having to write all that boilerplate property code seems redundant and a waste of time. What made it more frustrating was that C# 3.0 introduced auto-implemented properties, which allowed C# developers to create such simple properties with far less syntax. For more information on C#'s auto-implemented properties, consult Auto-Implemented Properties (C# Programming Guide).

The good news is that VB 2010 now has auto-implemented properties! You can turn the above property and private member variable declarations into just two lines of code using this new feature. To use auto-implemented properties use the following syntax:


Property PropertyName As Type

That's all there is to it! The screen shot below shows the much more concise property syntax for the Product class created above. Note how auto-implemented properties allowed us to reduce the property-related lines of code from 18 down to two!


Auto-implemented properties have been added to Visual Basic 2010.

Auto-implemented properties are an example of syntactic sugar - the new syntax makes the code easier to read and write for us developers, but, behind the scenes, it's business as usual. Specifically, the VB compiler automatically converts the auto-implemented property syntax into a private member variable and an expanded property with getters and setters.

One thing to note is that there are some subtle differences between VB's auto-implemented properties and C#'s. C# allows for read-only and write-only auto-implemented properties; it also allows different access methods (public, private, etc.) for the getters and setters. Visual Basic does not provide such flexibility. If you need to define read-only or write-only properties, or need different accessibility levels for the getter and setter, you'll need to use the expanded property definition syntax. However, with Visual Basic's auto-implemented properties you can specify an initial value for the property like so:


Property PropertyName As Type = Initial_Value

The following screen shot shows the syntax to specify an initial value for the ProductName and UnitCost properties in the Person class, namely "Chai" and 4.95, respectively.


Auto-implemented properties can have an initial value specified.

Collection Initializers

Both C# 3.0 and Visual Basic 9 introduced object initializers, which allow developers to declare and assign default values to the new object's properties all in one statement. C# 3.0 also added collection initializers, which allow developers to declare a collection and add elements to it in one statement; unfortunately, VB 9 did not include support for collection initializers. The good news is that collection initializers have been added to Visual Basic 2010!

Prior to VB 2010, creating a collection and specifying its elements required quite a few lines of code. The following code snippet shows the declaration of a List of Integers named Fib that is populated with the first eight Fibonacci numbers:


Dim Fib As New List(Of Integer)



Fib.Add(0)

Fib.Add(1)

Fib.Add(1)

Fib.Add(2)

Fib.Add(3)

Fib.Add(5)

Fib.Add(8)

Fib.Add(13)

Using collection initializers, the above syntax can be greatly compressed. Use the From keyword to specify the collection's initial elements. The following screen shot shows VB 2010 code that uses collection initializers to reduce the sheer volume of code and to improve the code's readability.


Specify the initial elements in a collection using VB 2010's collection initializers.

And, if you like, you can also use implicit line continuation to separate out the initial values on separate lines:


You can use implicit line continuation with the collection initializer syntax.


Conclusion

With it's release of Visual Studio 2010 and the .NET Framework 4, Microsoft has also released the latest versions of its two most popular .NET programming languages: C# and Visual Basic. Over the past couple of years Microsoft has worked to help unify the C# and Visual Basic feature sets and to ensure that these two languages grow together. To this end, Visual Basic has been updated with a number of language enhancements that were previously added to C#, including implicit line continuation, auto-implemented properties, and collection initializers. Conversely, C# has been updated to include a number of VB features that were previously missing. A future article will explore these C# 4.0 additions

20 April, 2010

Ban HTML comments from your pages and views

Ban HTML comments from your pages and views:

Too many people don’t realize that there are other options than <!-- --> comments to annotate HTML. These comments are harmful because they are sent to the client and thus make your page heavier than it needs to be.

Replacing client comments with server comments.When doing ASP.NET, a simple drop-in replacement is server comments, which are delimited by <%-- --%> instead of <!-- -->. Those server comments are visible in your source code, but will never be rendered to the client.

Here’s a simple way to sanitize a web site. From Visual Studio, hit CTRL+H to bring the search and replace dialog.

Choose “Replace in Files” from the second menu on top of the dialog. Open the find options, check “use” and make sure “Regular expressions” are selected. Use “*.aspx;*.ascx;” as the file types to examine. Choose “Entire Solution” under “Look in”.

Here’s the expression to search for comments:

\<!--{[^-]*}--\>

And here’s the replacement string:

<%--\1--%>

I usually use the “Find Next” and “Replace” buttons rather than the more brutal “Replace All” in order to not apply the fix blindingly. Once this is done, I do a second manual pass of finds with the same expression to make sure I didn’t miss anything.

C# 4.0: Dynamic Programming

C# 4.0: Dynamic Programming: " By Paulo Morgado ASP.Net Weblogs
The major feature of C# 4.0 is dynamic programming. Not just dynamic typing, but dynamic in broader sense, which means talking to anything that is not statically typed to be a .NET object.

Dynamic Language Runtime

The Dynamic Language Runtime (DLR) is piece of technology that unifies dynamic programming on the .NET platform, the same way the Common Language Runtime (CLR) has been a common platform for statically typed languages.
The CLR always had dynamic capabilities. You could always use reflection, but its main goal was never to be a dynamic programming environment and there were some features missing. The DLR is built on top of the CLR and adds those missing features to the .NET platform.
Dynamic Language Runtime
The Dynamic Language Runtime is the core infrastructure that consists of:

  • Expression Trees
    The same expression trees used in LINQ, now improved to support statements.

  • Dynamic Dispatch
    Dispatches invocations to the appropriate binder.

  • Call Site Caching
    For improved efficiency.
Dynamic languages and languages with dynamic capabilities are built on top of the DLR. IronPython and IronRuby were already built on top of the DLR, and now, the support for using the DLR is being added to C# and Visual Basic. Other languages built on top of the CLR are expected to also use the DLR in the future.
Underneath the DLR there are binders that talk to a variety of different technologies:

  • .NET Binder
    Allows to talk to .NET objects.

  • JavaScript Binder
    Allows to talk to JavaScript in SilverLight.

  • IronPython Binder
    Allows to talk to IronPython.

  • IronRuby Binder
    Allows to talk to IronRuby.

  • COM Binder
    Allows to talk to COM.
Whit all these binders it is possible to have a single programming experience to talk to all these environments that are not statically typed .NET objects.

The dynamic Static Type

Let’s take this traditional statically typed code:
Calculator calculator = GetCalculator();
int sum = calculator.Sum(10, 20);



Because the variable that receives the return value of the GetCalulator method is statically typed to be of type Calculator and, because the Calculator type has an Add method that receives two integers and returns an integer, it is possible to call that Sum method and assign its return value to a variable statically typed as integer.


Now lets suppose the calculator was not a statically typed .NET class, but, instead, a COM object or some .NET code we don’t know he type of. All of the sudden it gets very painful to call the Add method:


object calculator = GetCalculator(); Type calculatorType = calculator.GetType(); object res = calculatorType.InvokeMember("Add", BindingFlags.InvokeMethod, null,
calculator, new object[] { 10, 20 }); int sum = Convert.ToInt32(res);


And what if the calculator was a JavaScript object?


ScriptObject calculator = GetCalculator();
object res = calculator.Invoke("Add", 10, 20);
int sum = Convert.ToInt32(res);


For each dynamic domain we have a different programming experience and that makes it very hard to unify the code.


With C# 4.0 it becomes possible to write code this way:


dynamic calculator = GetCalculator();
int sum = calculator.Add(10, 20);



You simply declare a variable who’s static type is dynamic. dynamic is a pseudo-keyword (like var) that indicates to the compiler that operations on the calculator object will be done dynamically.


The way you should look at dynamic is that it’s just like object (System.Object) with dynamic semantics associated. Anything can be assigned to a dynamic.


dynamic x = 1;
dynamic y = "Hello";
dynamic z = new List<int> { 1, 2, 3 };



At run-time, all object will have a type. In the above example x is of type System.Int32.


When one or more operands in an operation are typed dynamic, member selection is deferred to run-time instead of compile-time. Then the run-time type is substituted in all variables and normal overload resolution is done, just like it would happen at compile-time.


The result of any dynamic operation is always dynamic and, when a dynamic object is assigned to something else, a dynamic conversion will occur.


CodeResolutionMethod

double x = 1.75;
double y = Math.Abs(x);


compile-time


double Abs(double x)


dynamic x = 1.75;
dynamic y = Math.Abs(x);


run-time


double Abs(double x)


dynamic x = 2;
dynamic y = Math.Abs(x);     


run-time


int Abs(int x)



The above code will always be strongly typed. The difference is that, in the first case the method resolution is done at compile-time, and the others it’s done ate run-time.


IDynamicMetaObjectObject

The DLR is pre-wired to know .NET objects, COM objects and so forth but any dynamic language can implement their own objects or you can implement your own objects in C# through the implementation of the IDynamicMetaObjectProvider interface. When an object implements IDynamicMetaObjectProvider, it can participate in the resolution of how method calls and property access is done.


The .NET Framework already provides two implementations of IDynamicMetaObjectProvider:



  • DynamicObject : IDynamicMetaObjectProvider

    The DynamicObject class enables you to define which operations can be performed on dynamic objects and how to perform those operations. For example, you can define what happens when you try to get or set an object property, call a method, or perform standard mathematical operations such as addition and multiplication.


  • ExpandoObject : IDynamicMetaObjectProvider

    The ExpandoObject class enables you to add and delete members of its instances at run time and also to set and get values of these members. This class supports dynamic binding, which enables you to use standard syntax like sampleObject.sampleMember, instead of more complex syntax like sampleObject.GetAttribute("sampleMember").

"

MS Ajax Libraries and Configured Assemblies

MS Ajax Libraries and Configured Assemblies: " By smehaffie ASP.Net Weblogs

Use Case

You have a brand new IIS servers that has .Net 3.5 installed and are migrating sites to the new servers. In the process of migrating sites you come across some sites that get an error about the version of AJAX libraries being references in the web.config. In the web.config all the entries reference 1.0.61025.0, but the older version of the AJAX libraries are not installed on the new servers, only the latest version is installed that comes with .Net 3.5. So what are the options to fix this issue.

Solutions

1) Install the older version of the AJAX Libraries: Although this works, IMO it is never a great idea to install an older version of a library after a newer version has been installed. Plus, if all new application use the latest versions, is it worth the effort of installing the older version for a few legacy applications?

2) Update the web.config files so all references use latest version (3.5.0.0): This option is very time consuming and error prone. In addition, you will also have to update any pages where there is a register tag for the older libraries as well. This would require you to redeploy any application that have this issue.

3) Use the Configured Assembly capabilities of .Net (aka: Assembly Bindings) to make any application that uses the older AJAX libraries to use the new AJAX libraries. IMO, this is the easiest, quickest and least invasive way to fix the issue. Below are the steps to implement this fix.

Solution #3

Do the following steps on the IIS servers that the issue is occurring. The 2 assemblies that need assemblies bindings created are: System.Web.Extension & System.Web.Extensions.Design

1) Go to Start - > All Program -> Administrative Tools -> Microsoft .NET Framework 2.0 Configuration.
2) Right click on 'Configured Assemblies' to view list of configured assemblies.
3) Left Click on right pane to bring up menu and choose 'Add'.
4) Make sure 'Choose and assembly from the assembly cache is checked' and click the 'Choose Assembly' button.
5) Choose System.Web.Extension (does not matter what version).
6) Click the 'Finish' button.
7) Binding Policy Tab
- Enter Requested Version = 1.0.61025.0
- Enter New Version = 3.5.0.0
8) Repeat steps 2-7 for the System.Web.Extensions.Design assembly.

-------------------------------------------------------------------------------------------------------------------------

Note: If 'Microsoft .NET Framework 2.0 Configuration does not exist under Admin tools use mmc to access it (see below)

1) Start -> Run -> Enter MMC
2) File - > Add/Remove Snap-In then Click "Add" button
3) Choose '.Net 2.0 Configuration' then click 'Add' button and then the 'Close' Button.
4) On 'Add/Remove Snapin' windows click the 'OK' Button.
5) Expand the tree on the right and you can start following the directions above for adding the configured assemblies.

--------------------------------------------------------------------------------------------------------------------------

16 April, 2010

Silverlight Toolbar and Menu Control - v2010 vol 1

Continuing our DXperience v2010.1 sneak peeks, we’ll now look at the new Toolbar and Menu Library - Bars.
Grown out of DXBars for WPF, this library is now an essential part of XPF. It will live in the DevExpress.Xpf.Core and will be used by other products in the suite where a menu UI is required.
Silverlight/WPF Toolbar and Menu Control
Main Menu and Toolbar Style Bars, Drag & Drop, Floating Bars and a build-in Microsoft Office Style Customization Window are all supported and the efforts to get data editors for Silverlight out first (in v2009.x) are now paying off :) W00t!
The key concepts of the Bars library did not change in XPF. And if you are coming from WinForms, you will find the same familiar structure (well in XAML of course :)).
<dxb:BarManager Name="barManager">
<dxb:BarManager.Categories>
<dxb:BarManagerCategory Name="Default" />
dxb:BarManager.Categories>
<dxb:BarManager.Items>
<dxb:BarButtonItem Name="fileNewMenuItem" CategoryName="File" Content="New" Glyph="New_16x16.png"/>
<dxb:BarButtonItem Name="fileOpenMenuItem" CategoryName="File" Content="Open" Glyph="Open_16x16.png"/>
<dxb:BarSubItem Name="fileMenuItem" CategoryName="Default" Content="File">
<dxb:BarSubItem.ItemLinks>
<dxb:BarButtonItemLink BarItemName="fileNewMenuItem"/>
<dxb:BarButtonItemLink BarItemName="fileOpenMenuItem"/>
<dxb:BarItemLinkSeparator>dxb:BarItemLinkSeparator>
<dxb:BarButtonItemLink BarItemName="fileCloseMenuItem"/>
dxb:BarSubItem.ItemLinks>
dxb:BarSubItem>
dxb:BarManager.Items>
<dxb:BarManager.Bars>
<dxb:Bar Caption="Main Menu" x:Name="menuBar" IsMainMenu="True" UseWholeRow="True">
<dxb:Bar.DockInfo>
<dxb:BarDockInfo ContainerType="Top"/>
dxb:Bar.DockInfo>
<dxb:Bar.ItemLinks>
<dxb:BarSubItemLink BarItemName="fileMenuItem"/>
dxb:Bar.ItemLinks>
dxb:Bar>
dxb:BarManager.Bars>

dxb:BarManager>

and embedding an editor…
<dxb:BarEditItem Name="editFontSizeItem" CategoryName="Format" Content="Font Size:">
<dxb:BarEditItem.EditSettings>
<dxes:ComboBoxEditSettings x:Name="fontSizeSettings"/>
dxb:BarEditItem.EditSettings>
dxb:BarEditItem>
YWVPJV9HDHHY

13 April, 2010

Visual Studio 2010 and .NET 4 Released

The final release of Visual Studio 2010 and .NET 4 is now available.



Download and Install Today

MSDN subscribers, as well as WebsiteSpark/BizSpark/DreamSpark members, can now download the final releases of Visual Studio 2010 and TFS 2010 through the MSDN subscribers download center.
If you are not an MSDN Subscriber, you can download free 90-day trial editions of Visual Studio 2010.
Or you can can download the free Visual Studio express editions of Visual Web Developer 2010, Visual Basic 2010, Visual C# 2010 and Visual C++. These express editions are available completely for free (and never time out). If you are looking for an easy way to setup a new machine for web-development you can automate installing ASP.NET 4, ASP.NET MVC 2, IIS, SQL Server Express and Visual Web Developer 2010 Express really quickly with the Microsoft Web Platform Installer (just click the install button on the page).

What is new with VS 2010 and .NET 4

Today’s release is a big one – and brings with it a ton of new feature and capabilities.
One of the things we tried hard to focus on with this release was to invest heavily in making existing applications, projects and developer experiences better. What this means is that you don’t need to read 1000+ page books or spend time learning major new concepts in order to take advantage of the release. There are literally thousands of improvements (both big and small) that make you more productive and successful without having to learn big new concepts in order to start using them.
Below is just a small sampling of some of the improvements with this release:
Visual Studio 2010 IDE
Visual Studio 2010 now supports multiple-monitors (enabling much better use of screen real-estate). It has new code Intellisense support that makes it easier to find and use classes and methods. It has improved code navigation support for searching code-bases and seeing how code is called and used. It has new code visualization support that allows you to see the relationships across projects and classes within projects, as well as to automatically generate sequence diagrams to chart execution flow.
The editor now supports HTML and JavaScript snippet support as well as improved JavaScript intellisense. The VS 2010 Debugger and Profiling support is now much, much richer and enables new features like Intellitrace (aka Historical Debugging), debugging of Crash/Dump files, and better parallel debugging. VS 2010’s multi-targeting support is now much richer, and enables you to use VS 2010 to target .NET 2, .NET 3, .NET 3.5 and .NET 4 applications. And the infamous Add Reference dialog now loads much faster.
TFS 2010 is now easy to setup (you can now install the server in under 10 minutes) and enables great source-control, bug/work-item tracking, and continuous integration support. Testing support (both automated and manual) is now much, much richer. And VS 2010 Premium and Ultimate provide much better architecture and design tooling support.
VB and C# Language Features
VB and C# in VS 2010 both contain a bunch of new features and capabilities. VB adds new support for automatic properties, collection initializers, and implicit line continuation support among many other features. C# adds support for optional parameters and named arguments, a new dynamic keyword, co-variance and contra-variance, and among many other features.
ASP.NET 4 and ASP.NET MVC 2
With ASP.NET 4, Web Forms controls now render clean, semantically correct, and CSS friendly HTML markup. Built-in URL routing functionality allows you to expose clean, search engine friendly, URLs and increase the traffic to your Website. ViewState within applications can now be more easily controlled and made smaller. Client IDs rendered by server controls can now be controlled. ASP.NET Dynamic Data support has been enhanced. More controls, including rich charting and data controls, are now built-into ASP.NET 4 and enable you to build applications even faster. New starter project templates now make it easier to get going with new projects. SEO enhancements make it easier to drive traffic to your public facing sites. And web.config files are now clean and simple.
ASP.NET MVC 2 is now built-into VS 2010 and ASP.NET 4, and provides a great way to build web sites and applications using a model-view-controller based pattern. ASP.NET MVC 2 adds features to easily enable client and server validation logic, provides new strongly-typed HTML and UI-scaffolding helper methods. It also enables more modular/reusable applications. The new <%: %> syntax in ASP.NET makes it easier to HTML encode output. Visual Studio 2010 also now includes better tooling support for unit testing and TDD. In particular, “Consume first intellisense” and “generate from usage" support within VS 2010 make it easier to write your unit tests first, and then drive your implementation from them.
Deploying ASP.NET applications gets a lot easier with this release. You can now publish your Websites and applications to a staging or production server from within Visual Studio itself. Visual Studio 2010 makes it easy to transfer all your files, code, configuration, database schema and data in one complete package. VS 2010 also makes it easy to manage separate web.config configuration files settings depending upon whether you are in debug, release, staging or production modes.
WPF 4 and Silverlight 4
WPF 4 includes a ton of new improvements and capabilities including more built-in controls, richer graphics features (cached composition, pixel shader 3 support, layoutrounding, and animation easing functions), a much improved text stack (with crisper text rendering, custom dictionary support, and selection and caret brush options). WPF 4 also includes a bunch of support to enable you to take advantage of new Windows 7 features – including multi-touch and Windows 7 shell integration.
Silverlight 4 will launch this week as well. You can watch my Silverlight 4 launch keynote streamed live Tuesday (April 13th) at 8am Pacific Time. Silverlight 4 includes a ton of new capabilities – including a bunch for making it possible to build great business applications and out of the browser applications. I’ll be doing a separate blog post later this week (once it is live on the web) that talks more about its capabilities.
Visual Studio 2010 now includes great tooling support for both WPF and Silverlight. The new VS 2010 WPF and Silverlight designer makes it much easier to build client applications as well as build great line of business solutions, as well as integrate and bind with data. Tooling support for Silverlight 4 with the final release of Visual Studio 2010 will be available when Silverlight 4 releases to the web this week.
SharePoint and Azure
Visual Studio 2010 now includes built-in support for building SharePoint applications. You can now create, edit, build, and debug SharePoint applications directly within Visual Studio 2010. You can also now use SharePoint with TFS 2010.
Support for creating Azure-hosted applications is also now included with VS 2010 – allowing you to build ASP.NET and WCF based applications and host them within the cloud.
Data Access
Data access has a lot of improvements coming to it with .NET 4. Entity Framework 4 includes a ton of new features and capabilities – including support for model first and POCO development, default support for lazy loading, built-in support for pluralization/singularization of table/property names within the VS 2010 designer, full support for all the LINQ operators, the ability to optionally expose foreign keys on model objects (useful for some stateless web scenarios), disconnected API support to better handle N-Tier and stateless web scenarios, and T4 template customization support within VS 2010 to allow you to customize and automate how code is generated for you by the data designer.
In addition to improvements with the Entity Framework, LINQ to SQL with .NET 4 also includes a bunch of nice improvements.
WCF and Workflow
WCF includes a bunch of great new capabilities – including better REST, activation and configuration support. WCF Data Services (formerly known as Astoria) and WCF RIA Services also now enable you to easily expose and work with data from remote clients.
Windows Workflow is now much faster, includes flowchart services, and now makes it easier to make custom services than before. More details can be found here.
CLR and Core .NET Library Improvements
.NET 4 includes the new CLR 4 engine – which includes a lot of nice performance and feature improvements. CLR 4 engine now runs side-by-side in-process with older versions of the CLR – allowing you to use two different versions of .NET within the same process. It also includes improved COM interop support.
The .NET 4 base class libraries (BCL) include a bunch of nice additions and refinements. In particular, the .NET 4 BCL now includes new parallel programming support that makes it much easier to build applications that take advantage of multiple CPUs and cores on a computer. This work dove-tails nicely with the new VS 2010 parallel debugger (making it much easier to debug parallel applications), as well as the new F# functional language support now included in the VS 2010 IDE. .NET 4 also now also has the Dynamic Language Runtime (DLR) library built-in – which makes it easier to use dynamic language functionality with .NET. MEF – a really cool library that enables rich extensibility – is also now built-into .NET 4 and included as part of the base class libraries.
.NET 4 Client Profile
The download size of the .NET 4 redist is now much smaller than it was before (the x86 full .NET 4 package is about 36MB). We also now have a .NET 4 Client Profile package which is a pure sub-set of the full .NET that can be used to streamline client application installs.
Visual C++
VS 2010 includes a bunch of great improvements for C++ development. This includes better C++ Intellisense support, MSBuild support for projects, improved parallel debugging and profiler support, MFC improvements, and a number of language features and compiler optimizations.




My VS 2010 and .NET 4 Blog Series

I’ve been cranking away on a blog series the last few months that highlights many of the new VS 2010 and .NET 4 improvements. The good news is that I have about 20 in-depth posts already written. The bad news (for me) is that I have about 200 more to go until I’m done! I’m going to try and keep adding a few more each week over the next few months to discuss the new improvements and how best to take advantage of them.
Below is a list of the already written ones that you can check out today:




Stay tuned to my blog as I post more. Also check out this page which links to a bunch of great articles and videos done by others.




VS 2010 Installation Notes

If you have installed a previous version of VS 2010 on your machine (either the beta or the RC) you must first uninstall it before installing the final VS 2010 release. I also recommend uninstalling .NET 4 betas (including both the client and full .NET 4 installs) as well as the other installs that come with VS 2010 (e.g. ASP.NET MVC 2 preview builds, etc). The uninstalls of the betas/RCs will clean up all the old state on your machine – after which you can install the final VS 2010 version and should have everything just work (this is what I’ve done on all of my machines and I haven’t had any problems).
The VS 2010 and .NET 4 installs add a bunch of new managed assemblies to your machine. Some of these will be “NGEN’d” to native code during the actual install process (making them run fast). To avoid adding too much time to VS setup, though, we don’t NGEN all assemblies immediately – and instead will NGEN the rest in the background when your machine is idle. Until it finishes NGENing the assemblies they will be JIT’d to native code the first time they are used in a process – which for large assemblies can sometimes cause a slight performance hit.
If you run into this you can manually force all assemblies to be NGEN’d to native code immediately (and not just wait till the machine is idle) by launching the Visual Studio command line prompt from the Windows Start Menu (Microsoft Visual Studio 2010->Visual Studio Tools->Visual Studio Command Prompt). Within the command prompt type “Ngen executequeueditems” – this will cause everything to be NGEN’d immediately.




How to Buy Visual Studio 2010

You can can download and use the free Visual Studio express editions of Visual Web Developer 2010, Visual Basic 2010, Visual C# 2010 and Visual C++. These express editions are available completely for free (and never time out).
You can buy a new copy of VS 2010 Professional that includes a 1 year subscription to MSDN Essentials for $799. MSDN Essentials includes a developer license of Windows 7 Ultimate, Windows Server 2008 R2 Enterprise, SQL Server 2008 DataCenter R2, and 20 hours of Azure hosting time. Subscribers also have access to MSDN’s Online Concierge, and Priority Support in MSDN Forums.
Upgrade prices from previous releases of Visual Studio are also available. Existing Visual Studio 2005/2008 Standard customers can upgrade to Visual Studio 2010 Professional for a special $299 retail price until October. You can take advantage of this VS Standard to Professional upgrade promotion here.
Web developers who build applications for others, and who are either independent developers or who work for companies with less than 10 employees, can also optionally take advantage of the Microsoft WebSiteSpark program. This program gives you three copies of Visual Studio 2010 Professional, 1 copy of Expression Studio, and 4 CPU licenses of both Windows 2008 R2 Web Server and SQL 2008 Web Edition that you can use to both develop and deploy applications with at no cost for 3 years. At the end of the 3 years there is no obligation to buy anything. You can sign-up for WebSiteSpark today in under 5 minutes – and immediately have access to the products to download.






Performing a case-sensitive search and replace in SQL 2000/2005

If you need to perform a case sensitive search and/or replace in an SQL 2000 or SQL 2005 database you need to use the correct collation method. In the situation I had today I needed to change some copy throughout a website, all of which is in a string resource table, but I had to be careful to maintian case used, i.e: ‘Shipping’ had to change to ‘Delivery’, but ’shipping’ had to change to ‘delivery’.
Your database may have been set up to use a case-sensitive collation method, or it may not have, or you may not have been involved in setup. I don’t know which collation method is the smartest in the world to use – I’m not a DBA – but here’s how to find out which collation you’re working with.
Execute this query in a query analyser:
select charindex('If the result is 0 you are in a case-sensitive collation mode', 'RESULT')
A 0 return result means you’re working with a case-sensitive collation mode. This means you can write your search/replace query (I’ll give an example below) without specifying the collation method you want to use and your query will consider ‘RESULT’ different to ‘result’.
If you DO have to specify a collation method you just have to declare it after the column name you’re interested in. Here’s an example:
update StringResource
set ConfigValue = replace(ConfigValue COLLATE Latin1_General_BIN, 'Shipping', 'Delivery')
from StringResource
where charindex('Shipping', configvalue COLLATE Latin1_General_BIN) > 0

update StringResource
set ConfigValue = replace(ConfigValue COLLATE Latin1_General_BIN, 'shipping', 'delivery')
from StringResource
where charindex('shipping', configvalue COLLATE Latin1_General_BIN) > 0
This query replaces the word ‘Shipping’ with ‘Delivery’ in the ConfigValue column in the StringResource table. There are two seperate statements, one for each case I’m replacing, because I need to specify the casing I’m concerned with explicitly. The important part of the collation type is the _BIN part, which specifies that I want to compare strings as binary data. More information about aspects of collation sorting here. This method may not be the smartest in the world so I would appreciate any comments.
 

12 April, 2010

Dynamic Paging and Sorting

Dynamic Paging and Sorting: By Ricardo Peres Asp.net WebLogs
Since .NET 3.5 brought us LINQ and expressions, I became a great fan of these technologies. There are times, however, when strong typing cannot be used - for example, when you are developing an ObjectDataSource and you need to do paging having just a column name, a page index and a page size, so I set out to fix this. Yes, I know about Dynamic LINQ, and even talked on it previously, but there's no need to add this extra assembly.
So, without further delay, here's the code, in both generic and non-generic versions:
public static IList ApplyPagingAndSorting(IEnumerable enumerable, Type elementType, Int32 pageSize, Int32 pageIndex, params String [] orderByColumns)
{
MethodInfo asQueryableMethod = typeof(Queryable).GetMethods(BindingFlags.Static | BindingFlags.Public).Where(m => (m.Name == "AsQueryable") && (m.ContainsGenericParameters == false)).Single();
IQueryable query = (enumerable is IQueryable) ? (enumerable as IQueryable) : asQueryableMethod.Invoke(null, new Object [] { enumerable }) as IQueryable;

if ((orderByColumns != null) && (orderByColumns.Length > 0))
{
PropertyInfo orderByProperty = elementType.GetProperty(orderByColumns [ 0 ]);
MemberExpression member = Expression.MakeMemberAccess(Expression.Parameter(elementType, "n"), orderByProperty);
LambdaExpression orderBy = Expression.Lambda(member, member.Expression as ParameterExpression);
MethodInfo orderByMethod = typeof(Queryable).GetMethods(BindingFlags.Public | BindingFlags.Static).Where(m => m.Name == "OrderBy").ToArray() [ 0 ].MakeGenericMethod(elementType, orderByProperty.PropertyType);

query = orderByMethod.Invoke(null, new Object [] { query, orderBy }) as IQueryable;

if (orderByColumns.Length > 1)
{
MethodInfo thenByMethod = typeof(Queryable).GetMethods(BindingFlags.Public | BindingFlags.Static).Where(m => m.Name == "ThenBy").ToArray() [ 0 ].MakeGenericMethod(elementType, orderByProperty.PropertyType);
PropertyInfo thenByProperty = null;
MemberExpression thenByMember = null;
LambdaExpression thenBy = null;

for (Int32 i = 1; i < orderByColumns.Length; ++i)
{
thenByProperty = elementType.GetProperty(orderByColumns [ i ]);
thenByMember = Expression.MakeMemberAccess(Expression.Parameter(elementType, "n"), thenByProperty);
thenBy = Expression.Lambda(member, member.Expression as ParameterExpression);
query = thenByMethod.Invoke(null, new Object [] { query, thenBy }) as IQueryable;
}
}
}

if (pageSize > 0)
{
MethodInfo takeMethod = typeof(Queryable).GetMethod("Take", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(elementType);
MethodInfo skipMethod = typeof(Queryable).GetMethod("Skip", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(elementType);

query = skipMethod.Invoke(null, new Object [] { query, pageSize * pageIndex }) as IQueryable;
query = takeMethod.Invoke(null, new Object [] { query, pageSize }) as IQueryable;
}

MethodInfo toListMethod = typeof(Enumerable).GetMethod("ToList", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(elementType);
IList list = toListMethod.Invoke(null, new Object [] { query }) as IList;

return (list);
}

public static List ApplyPagingAndSorting(IEnumerable enumerable, Int32 pageSize, Int32 pageIndex, params String [] orderByColumns)
{
return (ApplyPagingAndSorting(enumerable, typeof(T), pageSize, pageIndex, orderByColumns) as List);
}

List list = new List { new DateTime(2010, 1, 1), new DateTime(1999, 1, 12), new DateTime(1900, 10, 10), new DateTime(1900, 2, 20), new DateTime(2012, 5, 5), new DateTime(2012, 1, 20) };
List sortedList = ApplyPagingAndSorting(list, 3, 0, "Year", "Month", "Day");