带有WCF和控制台应用程序的DLL的ApplicationSettings

时间:2016-05-04 10:15:58

标签: dll web-config application-settings

我的项目包括一个Web服务(WCF)和一个在其他项目中使用公共库的控制台应用程序。 该库具有ApplicationSettings。 使用控制台应用程序,我只需要设置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="MyProject.Library.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  [...]
  <applicationSettings>
    <MyProject.Library.Properties.Settings>
      <setting name="EnvironmentMask" serializeAs="String">
        <value>RCT_</value>
      </setting>
    </MyProject.Library.Properties.Settings>
  </applicationSettings>
  [...]
</configuration>

我尝试做同样的一面Web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="MyCompany.ConfigurationGroup">
      <section name="SignedFileConfiguration" type="MyCompany.Web.SecureFileProxy.SignedFileConfigurationHandler, Net.MyCompany.Web" />
    </sectionGroup>
    <sectionGroup name="applicationSettings">
      <section name="MyProject.Library.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  [...]
  <MyCompany.ConfigurationGroup>
    <SignedFileConfiguration Secret="SecretKey!" PatternOfGeneratedUrl="http://www.myCompany.net/cgi/getFile.aspx?volume={0}&amp;path={1}&amp;token={2}&amp;name={3}" ConfiguratorType="MyCompany.Web.SecureFileProxy.SignedFileConfiguration, Net.MyCompany.Web">
      <Volumes>
        <add Name="fallow" PhysicalPath="" />
      </Volumes>
    </SignedFileConfiguration>
  </MyCompany.ConfigurationGroup>
  <applicationSettings>
    <MyProject.Library.Properties.Settings>
      <setting name="EnvironmentMask" serializeAs="String">
        <value>DEV_</value>
      </setting>
    </MyProject.Library.Properties.Settings>
  </applicationSettings>
  [...]
</configuration>

在执行Web服务期间,我收到一个异常:System.Configuration.SettingsPropertyNotFoundException和对象MyProject.Library.Properties.Settings为空

唯一一个谈论它的网站是https://littletalk.wordpress.com/2008/05/07/use-applicationsettings-in-web-application/,但它并不适合我。

我希望你能帮助我。 感谢您的关注 此致

1 个答案:

答案 0 :(得分:0)

我找到了这个问题的原因。

这是因为我使用了log4net,它有一个问题https://issues.apache.org/jira/browse/LOG4NET-398

我必须找到一种新方法。