2011-07-29 43 views
0

我嘗試從配置中加載System.Configuration.Configuration - 存儲在另一個位置(其他磁盤)上的文件。但是我得到以下...問題加載配置

例外: 創建SectionName的配置節處理程序時發生錯誤:無法加載文件或程序集「程序集」或其依賴項之一。

  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> 

回答

0

我只能猜想你試圖加載配置文件有一個@type屬性,它引用了一些組件,該組件是不是在你的應用程序bin文件夾一個/configuration/configSections/section

+0

但我嘗試加載在相同assmebly。我用更多的資料更新了我的問題。希望您能夠幫助我。 – dknaack

0

聽起來好像配置指定了一個程序集名稱'Assembly'。這可能是不正確的。如果您可以發佈c:\fancyFile.xml文件的內容,以便我們可以檢查該內容,將會有所幫助。

+0

我改變了這個問題。現在有一些來自xml文件的內容。謝謝! – dknaack