加载配置时出现问题

本文关键字:问题 配置 加载 | 更新日期: 2023-09-27 18:04:01

我尝试从存储在另一个位置(其他磁盘)的配置文件中加载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>

加载配置时出现问题

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

听起来好像配置指定了一个程序集名称' assembly '。这可能不正确。如果你能把c:'fancyFile.xml文件的内容贴出来,这样我们就可以检查一下了。