0

我正在尝试从另一个名为“Config”的程序集中加载 Unity 的配置设置,但是我运气不佳。

var fileMap = new ConfigurationFileMap("assembly://Config/Config/Unity.config"); 
System.Configuration.Configuration configuration = onfigurationManager.OpenMappedExeConfiguration(fileMap as ExeConfigurationFileMap, ConfigurationUserLevel.None);
var unitySection = (UnityConfigurationSection)configuration.GetSection("unity");

有什么建议么?

4

1 回答 1

1

试试这个作为一种解决方法。

在您的代码中:

  var container = new UnityContainer();
            var path = ConfigurationManager.AppSettings["UnityPath"].ToString();
            var map = new ExeConfigurationFileMap();
            map.ExeConfigFilename = path; 
            var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
            UnityConfigurationSection section = (UnityConfigurationSection)config.GetSection("unity");

在您的配置文件中:

<appSettings>
    <add key ="UnityPath" value="C:\PathToYourConfigFile\Unity.Config"/>
  </appSettings>
于 2012-05-02T15:08:24.337 回答