title: IISExpress 8 with custom configuration file - web service won't load
body: <p>When I develop a WCF service or website solution, I always use IISExpress with a custom configuration file so I can share the setup with other developers in the team. Basically, I run a batch file with the following command in it:</p>
  
  <p>"C:\Program Files (x86)\IIS Express\iisexpress.exe" /config:service-hosts.config</p>
  
  <p>Where service-hosts.config is the path to my custom configuration file.</p>
  
  <p>This method has been working perfectly fine, and still works fine in other solutions on my PC (each with their own service-hosts.config file). However, I've just started having a problem loading a WCF service using this method. I'm getting the following error when trying to browse to the service root dir, or any of the built in help endpoints:</p>
  
  <hr>
  
  <p>HTTP Error 500.19 - Internal Server Error
  The requested page cannot be accessed because the related configuration data for the page is invalid.</p>
  
  <p>Detailed Error Information:</p>
  
  <p>Module     IIS Web Core</p>
  
  <p>Notification       Unknown</p>
  
  <p>Handler    Not yet determined</p>
  
  <p>Error Code     0x80070003</p>
  
  <p>Config Error       Cannot read configuration file</p>
  
  <p>Config File    \?\D:\Projects\MyProject\WCFSite\web.config</p>
  
  <p>Requested URL      http:// localhost:80/</p>
  
  <p>Physical Path      </p>
  
  <p>Logon Method       Not yet determined</p>
  
  <p>Logon User     Not yet determined</p>
  
  <p>Request Tracing Directory      C:\Users\Spikeh\Documents\IISExpress\TraceLogFiles\</p>
  
  <p>Config Source:</p>
  
  <p>-1: </p>
  
  <pre><code>0: 
  </code></pre>
  
  <p>More Information:</p>
  
  <p>This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.</p>
  
  <p>If you see the text "There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined", this error is because you are running a .NET Framework 3.5-based application in .NET Framework 4. If you are running WebMatrix, to resolve this problem, go to the Settings node to set the .NET Framework version to ".NET 2". You can also remove the extra sections from the web.config file.</p>
  
  <p>View more information »</p>
  
  <hr>
  
  <p>I've been debugging for hours and can't get this error to change, let alone fix it.</p>
  
  <p>I've tried overwriting my service-hosts.config file with a few different versions of applicationHosts.config, running IISExspress in 64bit, replacing the web.config file with a very basic version, setting permissions on the directory (to the point where every user on my PC has access), and changing the app pool, but still no change.</p>
  
  <p>The weird thing is... when I change the WCF project to use "IISExpress" in the Web section of project properties, then subsequently debug the project, everything works fine... even with all of my web.config settings in place.</p>
  
  <p>This points to how I'm running IISExpress, or my service-hosts.config file... though the service-hosts.config file (with slight modifications for the sites involved) is exactly the same as it is in my other projects.</p>
  
  <p>One thing to note (might be a red herring), but I did downgrade the solution from VS2012 to VS2010, and changed the framework target to .Net 4.0... not sure if something might be configured funny due to that?</p>
  
  <p>Does anyone have any ideas? I'm at the point of jumping off the roof...</p>
  
  <p>UPDATE:</p>
  
  <p>Here's the debug information from IISExpress (running with /trace:e):</p>
  
  <pre><code>    Running IIS...
      Starting IIS Express ...
      Initializing the W3 Server Started CTC = 5514916
      PreInitSitesThread: Premature Exit Occured ( hr = 80070003 )
      W3 Server initializing WinSock.  CTC = 5514916
      W3 Server WinSock initialized.  CTC = 5514916
      W3 Server ThreadPool initialized (ipm has signalled).  CTC = 5514916
      Start listenerChannel http:0
      Successfully registered URL "http://*:80/" for site "MyWebsite" application "/"
      Registration completed for site "MyWebsite"
      AppPool 'MyCustomAppPool' initialized
      InitComplete event signalled
      IIS Express is running.
      Enter 'Q' to stop IIS Express
      IncrementMessages called
      Request ended: http://localhost:80/ with HTTP status 500.19
  </code></pre>
  
  <p>And here's the important part of my service-hosts.config:</p>
  
  <p></p>
  
  <pre><code>&lt;applicationPools&gt;
      &lt;add name="Clr4IntegratedAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_BIN%\config\templates\PersonalWebServer\aspnet.config" autoStart="true" /&gt;
      &lt;add name="Clr4ClassicAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_BIN%\config\templates\PersonalWebServer\aspnet.config" autoStart="true" /&gt;
      &lt;add name="Clr2IntegratedAppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_BIN%\config\templates\PersonalWebServer\aspnet.config" autoStart="true" /&gt;
      &lt;add name="Clr2ClassicAppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_BIN%\config\templates\PersonalWebServer\aspnet.config" autoStart="true" /&gt;
      &lt;add name="UnmanagedClassicAppPool" managedRuntimeVersion="" managedPipelineMode="Classic" autoStart="true" /&gt;
      &lt;add name="IISExpressAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_BIN%\config\templates\PersonalWebServer\aspnet.config" autoStart="true" /&gt;
  
      &lt;add name="MycustomAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" /&gt;
  
      &lt;applicationPoolDefaults managedRuntimeLoader="v4.0" &gt;
          &lt;processModel/&gt;
      &lt;/applicationPoolDefaults&gt;
  &lt;/applicationPools&gt;
  
  &lt;listenerAdapters&gt;
      &lt;add name="http" /&gt;
  &lt;/listenerAdapters&gt;
  
  &lt;sites&gt;
      &lt;site name="MyWebsite" id="1"&gt;
          &lt;application path="/" applicationPool="MyCustomAppPool"&gt;
              &lt;virtualDirectory path="/" physicalPath="D:\Projects\MyProject\WCFSite\" /&gt;
          &lt;/application&gt;
          &lt;bindings&gt;
              &lt;binding protocol="http" bindingInformation="*:80:" /&gt;
          &lt;/bindings&gt;
      &lt;/site&gt;
      &lt;siteDefaults&gt;
          &lt;logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" /&gt;
          &lt;traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" /&gt;
      &lt;/siteDefaults&gt;
      &lt;applicationDefaults applicationPool="Clr4IntegratedAppPool" /&gt;
      &lt;virtualDirectoryDefaults allowSubDirConfig="true" /&gt;
  &lt;/sites&gt;
  
  &lt;webLimits /&gt;
  </code></pre>
  
  <p></p>