locked
System.InvalidOperationException & System.TypeInitializationException from Infer.Net in an ASP.Net Web API 2 in an Azure web role RRS feed

  • Question

  • 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.

    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 System.InvalidOperationException with the explanation "An error occurred when trying to create a controller of type 'TwentyQuestionsController'. Make sure that the controller has a parameterless public constructor." (It does.)

    Looking into the detail of the exception the inner exception the next exception is System.TypeInitializationException ("The type initializer for 'GuessingGamesWebApplication.Controllers.TwentyQuestionsController' threw an exception") and further down the stack trace I see System.UnauthorizedAccessException ("Access to the path 'd:\windows\system32\inetsrv\GeneratedSource' is denied").

    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.

    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?

    (N.B. I'm using Infer.Net 2.6.41114.1 via NuGet.)

    Friday, January 9, 2015 8:35 AM

Answers

  • Got it. I've added the source folder path to the constructor on my Infer.Net model classes:

    public LiveDatabaseGamesEngines(string generatedSourceFolder = "MyGeneratedSourceFolder")
    {
        InferenceEngine.DefaultEngine.Compiler.GeneratedSourceFolder = generatedSourceFolder;
        // rest of code...
    }

    and then in my static constructor in my ASP.Net Web API 2 controller I can pass in the app path:

    var generatedSourceFolderPath = HostingEnvironment.MapPath("~/MyGeneratedSourceFolder");
    _GamesEngines = new LiveDatabaseGamesEngines(generatedSourceFolderPath);
    

    Friday, January 9, 2015 9:54 AM

All replies

  • Looking at this answer to the question "Can I write to file system on azure web site?" 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 d:\windows\system32\inetsrv\. How do I configure Infer.Net to do that?
    Friday, January 9, 2015 8:57 AM
  • Got it. I've added the source folder path to the constructor on my Infer.Net model classes:

    public LiveDatabaseGamesEngines(string generatedSourceFolder = "MyGeneratedSourceFolder")
    {
        InferenceEngine.DefaultEngine.Compiler.GeneratedSourceFolder = generatedSourceFolder;
        // rest of code...
    }

    and then in my static constructor in my ASP.Net Web API 2 controller I can pass in the app path:

    var generatedSourceFolderPath = HostingEnvironment.MapPath("~/MyGeneratedSourceFolder");
    _GamesEngines = new LiveDatabaseGamesEngines(generatedSourceFolderPath);
    

    Friday, January 9, 2015 9:54 AM