简体   繁体   English

读取Azure WebJob上的自定义ConfigurationSection时出错

[英]Error reading Custom ConfigurationSection on an Azure WebJob

I have a console application that has an app.config file with multiple ConfigurationSections 我有一个控制台应用程序,该应用程序具有一个带有多个ConfigurationSections的app.config文件

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: 可以在app.config文件中进行配置,如下所示:

<?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: 我能够将Webjob发布到Azure,并且在Webjob日志中看到以下错误:

[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. [09/13/2016 12:13:06> b4a151:ERR]未处理的异常:System.Configuration.ConfigurationErrorsException:为fulltextRepositorySection创建配置节处理程序时发生错误:无法加载文件或程序集“ NAMESPACE.WEBJOBNAME”或以下之一它的依赖性。 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. (D:\\ local \\ Temp \\ jobs \\ continuous \\ WEBJOBNAME \\ bcbcaozj.d0b \\ XXX.XXX.XXX.XXX.WEBJOBNAME.exe.config第4行)---> System.IO.FileNotFoundException:无法加载文件或程序集“ XXX.XXX.XXX.XXX.WEBJOBNAME”或其依赖项之一。 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]在System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost主机,字符串typeString,布尔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:错误]在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:错误]在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:错误]在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:错误]在System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(字符串configKey,Boolean&isRootDeclaredHere)[09/13/2016 12:13:06> b4a151:错误]-内部异常堆栈跟踪结束-

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere) [09/13/2016 12:13:06> b4a151:错误]在System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(字符串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:错误]在System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey,布尔值getLkg,布尔值checkPermission,布尔值getRuntimeObject,布尔值requestIsHere,对象和结果,对象和resultRuntimeObject)

[09/13/2016 12:13:06 > b4a151: ERR ] at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) [09/13/2016 12:13:06> b4a151:错误]在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:错误]在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]在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 [09/13/2016 12:13:06> b4a151:ERR]在C:\\ Install \\ agent-03_work \\ 10 \\ s \\ Src \\ PROJECTNAME中的NAMESPACE.Common.Configuration.ConfigurationLoader.LoadConfigurationSection [TSection](String sectionName) \\ Common \\ Configuration \\ ConfigurationLoader.cs:第28行

I can's seem to be able to read anything other than appsettings and connection strings from a webjob. 我似乎能够从webjob读取除appsettings和连接字符串以外的任何内容。 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. 可以将某些部分从config部分转换为appsettings(例如示例),但是有些诸如nlog的东西需要配置部分。 whould this be possible with webjobs or should I just use a VM? 谁可以通过webjobs进行操作,还是应该只使用VM?

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. System.Configuration.ConfigurationErrorsException:为fulltextRepositorySection创建配置节处理程序时发生错误:无法加载文件或程序集“ NAMESPACE.WEBJOBNAME”或其依赖项之一。 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. 通常,这意味着.NET程序集加载器找不到在配置文件的<section type="FULLNAMESPACE.ThrottlingConfigurationSection, FULLASSEMBLYNAME" name="fulltextRepositorySection" />中定义的名为“ FULLASSEMBLYNAME”的程序集。 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. (D:\\ local \\ Temp \\ jobs \\ continuous \\ WEBJOBNAME \\ bcbcaozj.d0b \\ XXX.XXX.XXX.XXX.WEBJOBNAME.exe.config第4行)---> System.IO.FileNotFoundException:无法加载文件或程序集“ XXX.XXX.XXX.XXX.WEBJOBNAME”或其依赖项之一。 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. 请尝试通过KUDU调试控制台检查错误消息中提到的路径中是否存在特定文件或程序集。

Additionally, I tested custom ConfigurationSection which is defined both in/outside the same assembly with WebJob project successfully both on my side and Azure. 此外,我测试了自定义ConfigurationSection,该自定义ConfigurationSection在WebJob项目的同一个程序集中的内部/外部都成功定义了在我这方面和Azure上。 Here is the code sample, you could refer to it. 这是代码示例,您可以参考它。

App.config 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 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM