.netazureazure-webjobsconfigurationsection

Error reading Custom ConfigurationSection on an Azure WebJob


I have a console application that has an app.config file with multiple ConfigurationSections

An example configuration section would be :

   public class ThrottlingConfigurationSection : ConfigurationSection, IThrottlingConfigurationSection
{
    private const string MillisecondsToThrottleProperty = "millisecondsToThrottle";

    /// <summary>
    /// Gets or sets the MillisecondsToThrottle.
    /// </summary>
    [ConfigurationProperty(MillisecondsToThrottleProperty, IsRequired = true)]
    public int MillisecondsToThrottle
    {
        get
        {
            return (int)this[MillisecondsToThrottleProperty];
        }

        set
        {
            this[MillisecondsToThrottleProperty] = value;
        }
    }
}

It is configured in the app.config file like so:

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <
        <section type="FULLNAMESPACE.ThrottlingConfigurationSection, FULLASSEMBLYNAME" name="fulltextRepositorySection" />
...
</configSections>
<fulltextRepositorySection millisecondsToThrottle="10" />
...
</configuration>

I was able to publis the webjob to Azure and in the webjob logs I see the following error:

[09/13/2016 12:13:06 > b4a151: ERR ] Unhandled Exception: System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for fulltextRepositorySection: Could not load file or assembly 'NAMESPACE.WEBJOBNAME' or one of its dependencies. The system cannot find the file specified. (D:\local\Temp\jobs\continuous\WEBJOBNAME\bcbcaozj.d0b\XXX.XXX.XXX.XXX.WEBJOBNAME.exe.config line 4) ---> System.IO.FileNotFoundException: Could not load file or assembly 'XXX.XXX.XXX.XXX.WEBJOBNAME' or one of its dependencies. The system cannot find the file specified.

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost host, String typeString, Boolean throwOnError)

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(FactoryRecord factoryRecord)

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere) [09/13/2016 12:13:06 > b4a151: ERR ] --- End of inner exception stack trace ---

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.ConfigurationManager.GetSection(String sectionName)

[09/13/2016 12:13:06 > b4a151: ERR ] at NAMESPACE.Common.Configuration.ConfigurationLoader.LoadConfigurationSection[TSection](String sectionName) in C:\Install\agent-03_work\10\s\Src\PROJECTNAME\Common\Configuration\ConfigurationLoader.cs:line 28

I can's seem to be able to read anything other than appsettings and connection strings from a webjob. any idea on how to do so? There are things that can be converted from config sections to appsettings (like the example) but there are things like nlog that need configuration sections. whould this be possible with webjobs or should I just use a VM?


Solution

  • System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for fulltextRepositorySection: Could not load file or assembly 'NAMESPACE.WEBJOBNAME' or one of its dependencies. The system cannot find the file specified.

    In general, this means that the .NET Assembly loader could not find the assembly called "FULLASSEMBLYNAME" which you defined in <section type="FULLNAMESPACE.ThrottlingConfigurationSection, FULLASSEMBLYNAME" name="fulltextRepositorySection" /> of your config file. Please make sure that the webjob works as expected on your side.

    (D:\local\Temp\jobs\continuous\WEBJOBNAME\bcbcaozj.d0b\XXX.XXX.XXX.XXX.WEBJOBNAME.exe.config line 4) ---> System.IO.FileNotFoundException: Could not load file or assembly 'XXX.XXX.XXX.XXX.WEBJOBNAME' or one of its dependencies. The system cannot find the file specified.

    Please try to check whether the specific file or assembly exists in the path which is mentioned in the error message via KUDU Debug console.

    Additionally, I tested custom ConfigurationSection which is defined both in/outside the same assembly with WebJob project successfully both on my side and Azure. Here is the code sample, you could refer to it.

    App.config

        <configSections>
          <!--ThrottlingConfigurationSection is defined in the same assembly within WebJob project which is called WebJobWithCustomConfig-->
          <section name="FulltextRepositorySection" type="WebJobWithCustomConfig.ThrottlingConfigurationSection,WebJobWithCustomConfig" />
          <!--ThrottlingConfigurationSection is defined in another assmebly outside of the WebJob project-->
          <section name="BruceConfigurationSection" type="Bruce.Configuration.ThrottlingConfigurationSection,Bruce.Configuration" />
        </configSections>
        <FulltextRepositorySection millisecondsToThrottle="10" />
        <BruceConfigurationSection millisecondsToThrottle="20" />
    

    Functions.cs

    [NoAutomaticTrigger]
    public static void ManualTrigger(int value)
    {
        ThrottlingConfigurationSection innerSection = (ThrottlingConfigurationSection)ConfigurationManager.GetSection("FulltextRepositorySection");
        Console.WriteLine("FulltextRepositorySection.MillisecondsToThrottle:{0}", innerSection.MillisecondsToThrottle);
    
        Bruce.Configuration.ThrottlingConfigurationSection outerSection= (Bruce.Configuration.ThrottlingConfigurationSection)ConfigurationManager.GetSection("BruceConfigurationSection");
        Console.WriteLine("BruceConfigurationSection.MillisecondsToThrottle:{0}", outerSection.MillisecondsToThrottle);
    }