System.IO.FileNotFoundException : Filename: redirection.config

Written by Troy on November 15, 2016 Categories: Uncategorized Tags: , ,

A quick note for anyone who is tripped up by this. I am working on a project that uses some rather groovy SpecFlow.Net system tests to perform and end-to-end test of a web service. I was trying to set this up on our TeamCity build server, and decided to leverage Microsoft.Web.Administration (ServerManager class) to manage the IIS set up.

Got everything working wonderfully on my local machine, checked in and… build fail.

The rather ambiguous exception was:

System.IO.FileNotFoundException : Filename: redirection.config
Error: Cannot read configuration file

Huh?

This error is caused by the IIS Express version of Microsoft.Web.Administration trying to find a local configuration file. Why is this even happening? I’m trying to use proper IIS!! On the build server, my assembly was referencing the wrong version of Microsoft.Web.Administration that it found in the GAC. I think Microsoft are trying to make life easy here. I get that IIS Express should be a transparent surrogate for IIS, but I think there is some flaws with this system. At least, please use some meaningful exception text! (Even the file path property of the exception is empty, which is weak. It would have provided a meaningful clue since ‘IISExpress’ is in the path).

To fix this issue, ensure when you reference C:\Windows\system32\inetsrv\Microsoft.Web.Administration.dll that you specify Specific Version=true. You can check your built assembly (with ILSpy or similar). The assembly should be 7.0 and note that the file version is “6.1.7601.17514″. If you’re reference to Microsoft.Web.Administration is 7.9 (file version 8.0.8418.0) then you’ve got the wrong one.

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>