【问题标题】:Problem loading Configuration加载配置时出现问题
【发布时间】:2011-07-29 12:53:58
【问题描述】:

我尝试从存储在另一个位置(另一个磁盘)的配置文件加载 System.Configuration.Configuration。但我得到以下...

例外: 为 SectionName 创建配置节处理程序时出错:无法加载文件或程序集“Assembly”或其依赖项之一。

            FileStream fileStream = new FileStream(@"c:\fancyFile.xml", FileMode.CreateNew);
            fileStream.Write(MyProject.Resources.Resource, 0, MyProject.Resources.Resource.Length);
            fileStream.Close();

            System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap(@"c:\fancyFile.xml");
            MyProject.Configuration conf = MyProject.Configuration.GetConfiguration(@"c:\fancyFile.xml").GetSection("MySection") as MyProject.Configuration;

  <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
          <section name="MySection" type="MyProject.Configuration, MyProject" allowLocation="true" allowDefinition="Everywhere"  />
      </configSections>
<MySection>

【问题讨论】:

    标签: c# .net configuration


    【解决方案1】:

    我只能推测您尝试加载的配置文件有一个 /configuration/configSections/section 和一个 @type 属性,它引用了一些不在您的应用程序 bin 文件夹中的程序集。

    【讨论】:

    • 但我尝试将其加载到同一个组件中。我已经用更多来源更新了我的问题。希望你能帮助我。
    【解决方案2】:

    听起来好像配置指定了“Assembly”的程序集名称。这可能是不正确的。如果您可以发布c:\fancyFile.xml 文件的内容以便我们检查这一点,将会很有帮助。

    【讨论】:

    • 我改变了问题。现在有一些来自 xml 文件的内容。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 2021-01-10
    • 2011-11-07
    • 2015-05-03
    • 1970-01-01
    相关资源
    最近更新 更多