title: System.InvalidOperationException & System.TypeInitializationException from Infer.Net in an ASP.Net Web API 2 in an Azure web role
body: <p>I have an ASP.Net Web API 2 project. In the controller in a static constructor an Infer.Net model gets initialised. When I run the project locally, either by choosing the web application as the start-up project in Visual Studio 2013 or by choosing the Azure Cloud Service project as the start-up project it works fine, the static constructor runs and the web API calls return the expected values.</p>
  
  <p>However when I deploy the site to Azure and try to call any of the web API controller's methods they fail and I get the exception <code>System.InvalidOperationException</code> with the explanation </p>
  
  <pre><code>An error occurred when trying to create a controller of type 'TwentyQuestionsController'. 
  Make sure that the controller has a parameterless public constructor.
  </code></pre>
  
  <p>(It does.)</p>
  
  <p>Looking into the detail of the inner exception the next exception is a <code>System.TypeInitializationException</code> </p>
  
  <pre><code>The type initializer for 'GuessingGamesWebApplication.Controllers.TwentyQuestionsController' 
  threw an exception
  </code></pre>
  
  <p>and further down the stack trace I see a <code>System.UnauthorizedAccessException</code> </p>
  
  <pre><code>Access to the path d:\windows\system32\inetsrv\GeneratedSource' is denied
  </code></pre>
  
  <p>It looks like when I run the project locally the web role process has sufficient privileges for Infer.Net to build and compile the local files that form the model but in Azure the web role process lacks those privileges.</p>
  
  <p>How do I deploy an ASP.Net Web API 2 web role to Azure with sufficient privileges for Infer.Net to build and compile the local files that form the model?</p>
  
  <p>(N.B. I'm using Infer.Net 2.6.41114.1 via NuGet.)</p>
  
  <p>========== EDIT ===========</p>
  
  <p>Looking at <a href="https://stackoverflow.com/a/12968226/575530">this answer</a> to the question <a href="https://stackoverflow.com/q/12964129/575530">Can I write to file system on azure web site?</a> the web role write permissions are limited to the root folder of my app. So an alternative solution would be to configure Infer.Net to write there instead of in <code>d:\windows\system32\inetsrv\</code>. How do I configure Infer.Net to do that?</p>