JoeJoe87577
JoeJoe87577

Reputation: 522

C# IIS programmatically site creation Missing Method

I've written a small tool that installs a web application and all needed software packages on a windows server. The tool creates application pools and the needed applications. On my development machine everything works fine, but on a test server (fresh w2k8r2 install with iis) the tool crashes with the following exception:

System.MissingMethodException: Method not found: 'Void Microsoft.Web.Administration.ApplocationPool.set_Startmode(Microsoft.Web.Administration.Startmode)'

This is the code I use to create the appPool:

using (ServerManager serverManager = new ServerManager())
{
    try
    {
        if (!serverManager.ApplicationPools.Any(x => x.Name == appPoolName))
        {
            ApplicationPool appPool = serverManager.ApplicationPools.Add(appPoolName);
            appPool.ManagedRuntimeVersion = "v4.0";
            appPool.StartMode = StartMode.AlwaysRunning;
            appPool.ProcessModel.IdentityType = ProcessModelIdentityType.LocalSystem;

            serverManager.CommitChanges();
        }

        result = true;
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
    }
}

I have installed the IIS managament tools and scripts with the server manager. Am I missing a package or is my code wrong?

Update:

As PhillipH wrote in his answer the IIS 7.5 does not support the property StartMode.

Upvotes: 2

Views: 1213

Answers (2)

hofi
hofi

Reputation: 111

You can check if the attribute exists:

var attr = appPool.Attributes.FirstOrDefault(a => a.Name == "startMode");
if (attr != null) attr.Value = 1; // OnDemand = 0;   AlwaysRunning = 1

Upvotes: 1

PhillipH
PhillipH

Reputation: 6222

I can only suggest your development machine isnt running IIS7.5, since 7.5 is the IIS that installs on Server 2008. ApplicationPool.StartMode is listed as a new feature of IIS8.

"Whats new in IIS8" https://blogs.msdn.microsoft.com/vijaysk/2012/10/09/iis-8-whats-new-application-pool-settings/

Upvotes: 2

Related Questions