【发布时间】:2023-03-27 13:00:01
【问题描述】:
我有一个控制台应用程序,它有一个 app.config 文件,其中包含多个 ConfigurationSections
一个示例配置部分是:
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;
}
}
}
在 app.config 文件中是这样配置的:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<
<section type="FULLNAMESPACE.ThrottlingConfigurationSection, FULLASSEMBLYNAME" name="fulltextRepositorySection" />
...
</configSections>
<fulltextRepositorySection millisecondsToThrottle="10" />
...
</configuration>
我能够将 webjob 发布到 Azure,并且在 webjob 日志中我看到以下错误:
[09/13/2016 12:13:06 > b4a151: ERR] 未处理异常:System.Configuration.ConfigurationErrorsException:为 fulltextRepositorySection 创建配置节处理程序时出错:无法加载文件或程序集“NAMESPACE.WEBJOBNAME”或其依赖项之一。该系统找不到指定的文件。 (D:\local\Temp\jobs\continuous\WEBJOBNAME\bcbcaozj.d0b\XXX.XXX.XXX.XXX.WEBJOBNAME.exe.config 第 4 行)---> System.IO.FileNotFoundException:无法加载文件或程序集'XXX.XXX.XXX.XXX.WEBJOBNAME' 或其依赖项之一。系统找不到指定的文件。
[09/13/2016 12:13:06 > b4a151: ERR ] 在 System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost 主机,字符串 typeString,布尔 throwOnError)
[09/13/2016 12:13:06 > b4a151: ERR ] 在 System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
[09/13/2016 12:13:06 > b4a151: ERR ] 在 System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
[09/13/2016 12:13:06 > b4a151: ERR ] 在 System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(FactoryRecord factoryRecord)
[09/13/2016 12:13:06 > b4a151: ERR ] 在 System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere) [09/13/2016 12:13:06 > b4a151: ERR ] --- 内部异常堆栈跟踪结束 ---
[09/13/2016 12:13:06 > b4a151: ERR ] 在 System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
[2016 年 9 月 13 日 12:13:06 > b4a151:ERR ] 在 System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串 configKey,布尔 getLkg,布尔 checkPermission,布尔 getRuntimeObject,布尔 requestIsHere,对象和结果,对象和 resultRuntimeObject)
[09/13/2016 12:13:06 > b4a151: ERR ] 在 System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
[09/13/2016 12:13:06 > b4a151: ERR ] 在 System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.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 ] 在 C:\Install\agent-03_work\10\s\ 中的 NAMESPACE.Common.Configuration.ConfigurationLoader.LoadConfigurationSection[TSection](String sectionName) Src\PROJECTNAME\Common\Configuration\ConfigurationLoader.cs:第 28 行
我似乎能够从网络作业中读取除 appsettings 和连接字符串之外的任何内容。关于如何做到这一点的任何想法?有些东西可以从配置部分转换为 appsettings(如示例),但有些东西需要配置部分,例如 nlog。网络作业可以做到这一点,还是我应该只使用虚拟机?
【问题讨论】:
-
它抱怨的程序集是否无法加载您使用 exe 部署的程序集?
-
另外,请尝试就地运行您的 WebJob 以查看是否有所作为。见this page
标签: .net azure azure-webjobs configurationsection