Search code examples
iisazure-web-rolesazure-cloud-services

Setting AppPool Identity on Windows Server 2016 @ Azure Cloud Service throw COMException “directory property cannot be found in the cache.”


The following code fail when executed on an Azure Guest OS Family 5 (Cloud Service webrole running Windows Server 2016):

using (var serverManager = new ServerManager())
{
    ApplicationPool applicationPool = serverManager.ApplicationPools.Add(name);
    applicationPool.AutoStart = true;
    applicationPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
    applicationPool.ManagedRuntimeVersion = "v4.0";

    // START ISSUE:
    applicationPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
    applicationPool.ProcessModel.UserName = username;
    applicationPool.ProcessModel.Password = userPassword;
    applicationPool.ProcessModel["idleTimeoutAction"] = 1;
    // END ISSUE

    serverManager.CommitChanges();
}

Exception:

System.Runtime.InteropServices.COMException: The directory property cannot be found in the cache.

More info

The exception is thrown at CommitChanges, but only when we have the code setting AppPool identity (the 4 lines between START ISSUE and END ISSUE). So this issue happen when setting AppPool identity.

This code have been in production for some years, working fine on on-prem Windows Servers and Azure Guest OS Family 4. We run the code with elevated privileges (using <Runtime executionContext="elevated"/>) and from the command line with administrative privileges. Same exception, but only on WinSrv2016 Azure cloud.

Workaround:

If we regenerate the machine keys on the deployment as described here, we stop experiencing this issue.

Question:

Is this an known issue on OS Family 5 Azure cloud service deployments that is being addressed? Any less obtrusive suggestions to work around this?


Solution

  • I also tested it on my side. When I set the App Pool Identity manually(Remote desktop to Web Role and reset the Identity using IIS Manager), I can reproduced the Keyset does not exist issue.

    enter image description here

    As described in the article which you post, the issue is caused by machine keys corrupt. I suggest you log this issue on cloud service feedback page.

    https://feedback.azure.com/forums/169386-cloud-services-web-and-worker-role