Reputation: 22275
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?
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
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
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,
Upvotes: 0