0
votes

Problem: ConfigurationManager does not work to access App.config in a v3.5 Azure WebJob

Question: How can I make it work?

* Background *

I have inherited a very old web application which must run as a Windows Azure Web App under a .Net 3.5 app pool.

There is a corresponding service which must be turned into an Azure WebJob (runs for several hours and requires access to the website files).

My problem is that the WebJob must be a .Net v3.5 application in order to run within the corresponding Web App (they both share the same App Pool so a v4.5 Web Job cannot be deployed to the v3.5 Web App).

This means I cannot use the normal WebJob NuGet packages such as Windows Azure Configuration Manager which I understand allows the System.Configuration.ConfigurationManager class to access App.config in the normal way, allowing referenced libraries containing EDMX based EntityFramework ObjectContexts to load their connection strings and app settings to be accessed by various bits of code all over the place. The code is shared between the web app and the web job so I need a method of configuration which is consistent across both.

Running the WebJob as a v4.5 allows it to work fine using ConfigurationManager but as soon as I switch to v3.5 (which I have to do to make the web app work) I have to remove all the incompatible WebJob Nuget packages including Windows Azure Configuration Manager. ConfigurationManager will no longer work to load AppSettings, no error, it just returns nothing for AppSettings.

My question is - how can I make ConfigurationManager work to load the deployed App.config without using those incompatible NuGet packages. I've looked at the code in Microsoft.WindowsAzure.Configuration.dll but I can't see how it make ConfigurationManager actually work, I must be looking in the wrong place.

1

1 Answers

1
votes

After running some v4.6 vs v3.5 app pool tests (exactly the same codebase - no NuGet packages installed apart from Azure WebJobs Publish) I have found that Web Jobs running in v3.5 app pools simply don't load their config files.

On a side note RSACryptoServiceProvider.ImportParameters also explodes under v3.5.

The following works to force the config file to load.

class Program
{
    static void Main()
    {
        AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"D:\home\site\wwwroot\App_Data\jobs\triggered\DataImportWebJob\[TheAppName].exe.config");

Thanks to Using ConfigurationManager to load config from an arbitrary location