Custom config section: Could not load file or assembly

前端 未结 7 2252
死守一世寂寞
死守一世寂寞 2020-12-15 05:50

I\'m having a very hard time trying to access a custom configuration section in my config file.

The config file is being read from a .dll that is loaded as a plug-in

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 06:19

    I tried AJ's answer, with rileywhite's supplement but I found that did not work for me.

    In my scenario, the custom ConfigurationSection class was already in the currently-executing assembly, and trying to load it causes a stack overflow. I also did not want to put it in GAC even though it did resolve the problem as reported by the OP.

    In end, I found this to work well enough for my purpose. Maybe others will find it useful:

    public class CustomConfigurationSection : ConfigurationSection {
      public CustomConfigurationSection()
      {
        var reader = XmlReader.Create();
        reader.ReadToDescendant("CustomConfigurationSection");
        base.DeserializeElement(reader,false);
      }
    
      // 
    }
    

提交回复
热议问题