以下是我加载程序集几种方法:
1.Assembly.Load(Assembly.GetExecutingAssembly().GetName().CodeBase + ".config");
2.Assembly.LoadFrom(Assembly.GetExecutingAssembly().GetName().CodeBase + ".config");
3.AppDomain domain = AppDomain.CreateDomain("mydomain");
  domain.ExecuteAssembly(Assembly.GetExecutingAssembly().GetName().CodeBase + ".config");
  AppDomain.Unload(domain);
4.AppDomain domain = AppDomain.CreateDomain("mydomain");
    domain.Load(Assembly.GetExecutingAssembly().GetName().CodeBase + ".config");
    AppDomain.Unload(domain);
用了好几种方法都是报下面的错误: 
Could not load file or assembly 'D:\\workspace\\projects\\datafeed\\impl\\datafeed\\trunk\\bin\\tmp\\datafeed-codegen.exe.config' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)会的大侠们帮下忙啊。。

解决方案 »

  1.   

    Assembly.Load用于加载程序集(*.exe,*.dll)'D:\\workspace\\projects\\datafeed\\impl\\datafeed\\trunk\\bin\\tmp\\datafeed-codegen.exe.config'不是程序集,只是个应用程序配置文件。
      

  2.   

    参考:读写配置文件*.config private void SaveConfig(string ConnenctionString)
            {
                XmlDocument doc=new XmlDocument();
                //获得配置文件的全路径
                string strFileName=AppDomain.CurrentDomain.BaseDirectory.ToString()+"Code.exe.config";
                doc.Load(strFileName);
                //找出名称为“add”的所有元素
                XmlNodeList nodes=doc.GetElementsByTagName("add");
                for(int i=0;i<nodes.Count;i++)
                {
                    //获得将当前元素的key属性
                    XmlAttribute att=nodes[i].Attributes["key"];
                    //根据元素的第一个属性来判断当前的元素是不是目标元素
                    if (att.Value=="ConnectionString") 
                    {
                        //对目标元素中的第二个属性赋值
                        att=nodes[i].Attributes["value"];
                        att.Value=ConnenctionString;
                        break;
                    }
                }
                //保存上面的修改
                doc.Save(strFileName);
            }
      

  3.   

    string configFile = Assembly.GetExecutingAssembly().CodeBase.Substring(8);
                config = ConfigurationManager.OpenExeConfiguration(configFile);
                KeyValueConfigurationCollection keyValue = ((AppSettingsSection)config.Sections["appSettings"]).Settings;
      

  4.   

    谢谢楼上的大侠。。
    我想问下 如果要加载datafeed-codegen.exe.config,有没有方法呢。。还是说这个文件本身就不能被加载?
    我用的是nant运行的。。
    default.build文件中包含如下内容。。我运行 nant gen-test-poco 的时候 才出现上述错误的。。
    <target name="gen-test-poco" depends="cleanup-test-poco, build-datafeed-codegen-exe, copy-lib-to-bin" >
        <loadtasks assembly="bin/tmp/datafeed-codegen.exe" />    <code_gen working_dir="Test\Spoke\Generated" use_vendor_code_as_schema="true">
          <references refid="build.datafeed.assemblies" />
        </code_gen>  </target>
      

  5.   

    我使用下面方法:
    c# 动态修改app.config文件