0

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.

  • Is the IIS open? While running this code? – Vivek Nuna Oct 13 '21 at 20:09
  • @viveknuna yes it is opened – Howard Chang Oct 13 '21 at 20:14
  • Can you please close then try running your code. It might be locking – Vivek Nuna Oct 13 '21 at 20:15
  • Yeah, but on the automated pipeline, IIS is closed and we also run into this issue. And we have resolved this issue by a kind of hack (iisreset), just want to know how to avoid this in code. Or the ServerManager class is just not robustly written? – Howard Chang Oct 13 '21 at 20:47
  • You are not supposed to use that NuGet package in the first place, https://blog.lextudio.com/whats-microsoft-web-administration-and-the-horrible-facts-you-should-know-b82f2c974da6 – Lex Li Oct 13 '21 at 22:31

0 Answers0