Iis7AppPool Start throws COMException

Feb 12, 2013 at 3:14 PM
I was getting a COMException: The object identifier does not represent a valid object from the Start action of the Iis7AppPool task. Google suggests this might be to do with the Windows Process Activation Service not being ready. I've forked the source and added the following method to catch the exception, wait 100ms and retry up to 3 times:
private void StartAppPoolWithRetry(int retryCount)
{
    try
    {
        this.pool.Start();
    }
    catch (COMException e)
    {
        if (e.Message.Contains("The object identifier does not represent a valid object")
            && retryCount < 3)
        {
            retryCount++;
            LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "..Sleeping and retrying {0}", retryCount));
            Thread.Sleep(100);
            StartAppPoolWithRetry(retryCount);
        }
        else
            throw;
    }
}
Then I'm calling StartAppPoolWithRetry(0) instead of this.pool.Start().
Coordinator
Feb 14, 2013 at 11:50 AM
Yes I've heard of this.

Thanks for the fix. What do you think of the following. I've increased the sleep to 1 second and removed the contains check as this won't work on non-english systems. I'm also logging a low importance message
    private void StartAppPoolWithRetry(int retryCount)
    {
        try
        {
            this.pool.Start();
        }
        catch (COMException e)
        {
            if (retryCount < 3)
            {
                retryCount++;
                this.LogTaskMessage(MessageImportance.Low, e.Message);
                this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "..Sleeping and retrying {0}", retryCount));
                Thread.Sleep(1000);
                this.StartAppPoolWithRetry(retryCount);
            }
            else
            {
                throw;
            }
        }
    }
if you are happy with that I will commit.
Feb 14, 2013 at 2:25 PM
Sounds great Mike, thanks a lot.
Coordinator
Feb 15, 2013 at 11:52 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Feb 15, 2013 at 11:54 AM
Marked as answer by mikeFourie on 10/15/2013 at 12:19 AM