c00000fd
c00000fd

Reputation: 22275

Proper way to include the Microsoft.Web.Administration assembly reference in VS 2010

I've encountered this problem earlier already. This time I was moving my development environment from one desktop to another and the issue came back. Note that to move my solution from the old environment to the new one I copied its entire solution folder. When opened in a new desktop, using the same version of the Visual Studio 2010, the following code:

using (ServerManager serverManager = new ServerManager())
{
    //Go through all the sites
    for (int s = 0; s < serverManager.Sites.Count; s++) //EXCEPTION HERE!!!
    {
        //Do work
    }
}

Produced this exception:

GetAdminSection; GetSectionInternal; SitesSectionCreator; Initialize;
SitesCollectionCreator; Initialize; collectData.
Filename: redirection.config 
Error: Cannot read configuration file

Why would it do so if it was running absolutely fine on an old desktop... Anyway, my question:

What is the proper way to include the Microsoft.Web.Administration assembly reference?

enter image description here

The way I currently did it is by linking to this dll via Solution -> References -> Add reference -> Browser and then point to this file:

C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll

My concern is that this exception will pop up on a production machine when my solution is deployed there.

Upvotes: 1

Views: 6677

Answers (2)

Andrew
Andrew

Reputation: 3796

Yes, it is correct way of referencing the Microsoft.Web.Administration assembly. It is only available for IIS 7.0 and later though. Do you have IIS features installed (go to Turn Windows features on or off wizard in your control panel).

http://www.iis.net/learn/manage/scripting/how-to-use-microsoftwebadministration

This is how I instantiate the ServerManager, had similar issues similar to yours:

ServerManager iisManager = ServerManager.OpenRemote(Environment.MachineName.ToLower());

Upvotes: 1

Lex Li
Lex Li

Reputation: 63183

The correct way to use this assembly is to add the reference after installing IIS. So what you have done is right.

The deployment concern is unnecessary, as you can always create a deployment package (MSI for example), so make sure that IIS is set as prerequisite and the expected assembly is present when your application finally runs. (Microsoft does register this assembly to GAC.)

About the exception you need to collect more information,

  1. At runtime which copy of Microsoft.Web.Administration is loaded? There can be multiple versions in GAC.
  2. Does the redirection.config file contain proper data? Are the file permissions correct?
  3. Does the issue remain if you run Visual Studio as administrator?

Upvotes: 0

Related Questions