8/27/2012

TFS 2012 Build Server Installation - Fails with error "System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list."

If you get during the TFS 2012 Build Server Configuration an error message with the following error message:

"System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list."

This is a bug in the Build Server configuration tool. You can fix it by turning on your Windows Firewall.

The configuration tool tries to check the firewall and add an exceptional rule for the build server port which causes an exception because the firewall is not running. Microsoft actually handles this exception, but within the catch block they try to write a warning message out which unfortunately causes another exception.

Here are the results by using reflector:

Assembly: Microsoft.TeamFoundation.Build.Config.dll
Name: Microsoft.TeamFoundation.Build.Config, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Class: BuildServiceHostUtilities
private static void RemovePermissions(Uri baseUrl, bool deleteFirewallException)
{
    if (baseUrl != null)
    {
        string permissionedUrl = GetPermissionedUrl(baseUrl);
        try
        {
            ConfigurationHelper.FreeUrlPrefix(permissionedUrl);
        }
        catch (Exception exception)
        {
            LogWarning(Resources.Format("CannotFreeUrlPrefix", new object[] { permissionedUrl, exception.Message }));
        }
        if (deleteFirewallException)
        {
            try
            {
                ConfigurationHelper.DisableFirewallException(baseUrl.Port);
            }
            catch (COMException exception2)
            {
                if (exception2.ErrorCode != -2147023143)
                {
                    LogWarning(Resources.Format("FailedDeletingPortExceptionFor", new object[] { baseUrl.Port, ExceptionFormatter.FormatExceptionForDisplay(exception2) }));
                }
            }
        }
    }
}

The RemovePermissions method in the BuildServiceHostUtilities tries to add an exception for the Build Service port in the line ConfigurationHelper.DisableFirewallException(baseUrl.Port);

This causes an COMException which will be just logged as an warning. So far so good. But unfortunately the call for formatting the warning message gets just two parameters passed. If we take a log in the resources of the dll the "FailedDeletingPortExceptionFor" text has 3 parameters defined:

Resources.Format("FailedDeletingPortExceptionFor", new object[] { baseUrl.Port, ExceptionFormatter.FormatExceptionForDisplay(exception2) });

FailedDeletingPortExceptionFor=Failed to remove firewall exception {1} for port {0}. Details: {2}

This finally causes the "System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.".

No comments:

Post a Comment