Upgrade to ASP.Net 4 on Web Farm

Recently we upgraded Web Farm web site to ASP.Net 4.
We studied .NET Framework 4 Migration Issues and, fortunately, didn’t found any serious issues, related to our site.

Before all sites will be converted to .Net 4, for forms authentication cookies to work across .NET Framework versions, we’ve added

<system.web>

<machineKey validation=”SHA1″ />

</system.web>
Tests were successfull on single computer, but when we started to test new version on Web Farm, we started to see intermittent strange errors.
Finally it was found, that the problem was that .Net4 has it’s own copy of machine.config, and machineKey validationKey=”0000…0000″ and decryptionKey=”00…00″ were not copied from  ASP.Net2 copy of machine.config
Note that “for a web farm, you want to manually put in your own keys and make sure they are EXACTLY THE SAME on each machine in the farm.”(Generate Machine Key Elements for Web Farms )

 

We had to manually copy <machineKey> entry to .Net4 copy of machine.config on each machine in the farm.


Advertisements

OutOfMemoryException in Microsoft WSE 3.0 Diagnostics.TraceInputFilter

We are still using Microsoft WSE 3.0 and on test server started to get
 
Event Type:        Error

Event Source:    Microsoft WSE 3.0

WSE054: An error occurred during the operation of the TraceInputFilter: System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.

   at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)

   at System.Text.StringBuilder.GetThreadSafeString(IntPtr& tid)

   at System.Text.StringBuilder.set_Length(Int32 value)

   at System.Xml.BufferBuilder.Clear()

   at System.Xml.BufferBuilder.set_Length(Int32 value)

   at System.Xml.XmlTextReaderImpl.ParseText()

   at System.Xml.XmlTextReaderImpl.ParseElementContent()

   at System.Xml.XmlTextReaderImpl.Read()

   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)

   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)

   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)

   at System.Xml.XmlDocument.Load(XmlReader reader)

   at System.Xml.XmlDocument.Load(Stream inStream)

   at Microsoft.Web.Services3.Diagnostics.TraceInputFilter.OpenLoadExistingFile(String path)

   at Microsoft.Web.Services3.Diagnostics.TraceInputFilter.Load(String path)

   at Microsoft.Web.Services3.Diagnostics.TraceInputFilter.TraceMessage(String messageId, Collection`1 traceEntries).

 

After investigation it was found, that the problem related to trace files, that become too big. When they were deleted and new files were created, error gone.

 

IsNullOrDefault generic helper function for nullable types

I’ve wrote  IsNullOrDefault generic helper function
 
    public  static bool IsNullOrDefault<T>(this Nullable<T> param) where T : struct
    {
        T deflt = default(T);
        if (!param.HasValue)
            return true;
        else if (param.Value.Equals(deflt))
            return true;
        return false;
    }
, but then realized that there is more short implementation on stackoverflow submitted by Josh
public static bool IsNullOrDefault<T>(this Nullable<T> value) where T : struct 
{ 
   
return default(T).Equals( value.GetValueOrDefault() ); 
} 
 
public static bool IsValue<T>(this Nullable<T> value, T valueToCheck) where T : struct 
{ 
   
return valueToCheck.Equals((value ?? valueToCheck)); 
} 

 

Helper methods StartOfMonth and StartOfNextMonth

 There are couple methods recently added to My DateTimeHelper class
    public static DateTime StartOfMonth(this DateTime dateValue)
        {
            return new DateTime(dateValue.Year,dateValue.Month,1,0,0,0);
        }
        public static DateTime StartOfNextMonth(this DateTime dateValue)
        {
            return StartOfMonth(dateValue).AddMonths(1);
        }

 

My version of UnhandledExceptionModule

I’ve created my own version of UnhandledExceptionModule independantly of codePlex project in 2007,

I’ve used code from http://support.microsoft.com/kb/911816

with considerations from http://www.eggheadcafe.com/articles/20060305.asp  

and done some refactoring. It also allows to use AppSettings[“EventLogSourceName”]
 
The zip file also includes TestUnhandledExceptionWAP test project, that I used to investigate issue
 
I’ve upload the code as patch here

VS 2010 snippet manager and quickCode

 

During the last few years I’ve used QuickCode and it was very helpful.

Visual Studio 2010 has  Code Snippets Manager that MS finally made quite convenient to use, so I will use it in a future.
 
I will need to convert my QuickCode commands to VS snippets.
I am sure I will miss Alt-Q hotkey for some time.
 
Code snippets links:

How to “cast” from generic List to ArrayList

We are writing new code using generic List<> , e.g. List<MyClass>.
 
However we have legacy functions, that are expect ArrayList as a parameter.
It is a second time, when I and my colleague asked, how to “cast” generic List<MyClass> to ArrayList.
The answer is simple- just use ArrayList constructor with ICollection parameter.
Note that it is not real cast, it  copies  references to ArrayList.

var list=new List<MyClass>();

//Fill list items
ArrayList al=new ArrayList(list);//”cast”- 
 
If you need opposite operation –Convert ArrayList to a Generic List,
you can filter all elements of arrayList that can be cast to the same type using Enumerable.OfType(Of TResult) Method
 
List<MyClass> typedList = arrayList.OfType<MyClass>().ToList();