When applying code like
using (ServerManager serverManager = new ServerManager())
{
var site = serverManager.Sites.SingleOrDefault(s => s.Name == siteName);
// some logic to add sites, set application pool.
// But not creating new ServerManager instances.
serverManager.CommitChanges();
}
it would be some chances throw exceptions
System.IO.FileLoadException: Filename: \\?\C:\windows\system32\inetsrv\config\applicationHost.config
Error: Cannot commit configuration changes because the file has changed on disk
at Microsoft.Web.Administration.Interop.IAppHostWritableAdminManager.CommitChanges()
at Microsoft.Web.Administration.ConfigurationManager.CommitChanges()
at Microsoft.Web.Administration.ServerManager.CommitChanges()
We have also tried to move away from using
clause and use a singleton ServerManager
, but the same issue is still there.
We are using Microsoft.Web.Administration 11.0.0 package.
Currently, we fixed it by catch the serverManager.CommitChanges()
and apply iisreset
in catch.
But it would be good if anybody knows the root cause/ how to fix it.