November 2007 - Posts

The Worst Bug Ever
26 November 07 06:24 AM | danieb | 1 comment(s)

I do support on a SharePoint Portal (2003, Framework 1.1). Last week after we deployed some new functionality we started to get very strange errors. The portal would just break at random arbitrary functions. I traced the root cause to the following warning in the System Event Log:

A process serving application pool 'X' suffered a fatal communication error with the World Wide Web Publishing Service. The process id was 'X'. The data field contains the error number.

After investigating the application log for hours, days I found nothing but errors caused by the chain reaction of error in the application log. However we would receive this error quite often.

Common Language Runtime detected an invalid program.

Then eventually it logged an error that basically said that it’s failing to compile a temporary file.

Cannot execute a program. The command being executed was "c:\windows\microsoft.net\framework\v1.1.4322\csc.exe" /noconfig @"C:\WINDOWS\TEMP\lannijk8.cmdline".

Thinking I had found the problem I delete the windows temp and the Asp.net temp directories. However a couple hours later the error was back, but not logging the Compile issue, only the warning in the system event log.  Googling the errors, didn’t return anything that made any sense.

Eventually we figured out (after reading this article) that when I added an extra Web Method to an existing web service, the generated Web Service had too many local variables.  I don’t know what the exact number is for .net 1.1 but for 2.0 its 32767, which is really a lot.

See .net declares a local variable for each method and parameter in your web service and compiles this class.

So we resolved the issue by removing some of the web methods, but if this is not an option there's a hotfix available to raise that limit to 4 million.

Using Generics, Anonymous Methods and Delegates to join.
20 November 07 04:54 PM | danieb | with no comments
/// <summary>
/// Delegate used to in Join
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <returns></returns>
public delegate object JoinDelegate<T>(T obj);
/// <summary>
/// Anonymous Method Delegate Join
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="items"></param>
/// <param name="join"></param>
/// <param name="delimiter"></param>
/// <returns></returns>
public static string Join<T>(IEnumerable items, JoinDelegate<T> join, string delimiter)
{   
    StringWriter sw = new StringWriter();
    bool firstTime = true;
    foreach (T t in items)   
    {
        if (firstTime)
            firstTime = false;
        else
            sw.Write(delimiter);
         sw.Write(join.Invoke(t));
    }
    return sw.ToString();

}

public struct StructTest
{
    public StructTest(string ID){this.id = ID;}
    public string id;
}[TestMethod]
public void Test_GenericJoin()
{
    StructTest[] items = new StructTest[] { new StructTest("1"),
                                            new StructTest("2") };
    string result = StringHelper.Join<StructTest>(items,
                               delegate (StructTest item)
{ return item.id;});
    Assert.AreEqual("1,2", result);

}