title: Changing app.configuration file during installation process with visual studio installer fails: Could not load file or assembly 'EntityFramework'
body: <p>Project Info: We are creating an installer project that allows users to choose a servername and databasename. After installation of the main program a corresponding database will be created.</p>
  
  <p>Installer project :</p>
  
  <ul>
  <li>Has an additional UI screen with two textboxes, containing servername and
  databasename.</li>
  <li>An custom action will be executed on installation and has the servername and databasename defined as custom action data.</li>
  </ul>
  
  <p>Main application:</p>
  
  <ul>
  <li>An installer class wires the after-installation event. This class will automatically be executed during installation. The custom action data will be passed as paramaters to this class.</li>
  <li>After-installation event will trigger a method that:
  
  <ul>
  <li>Creates the database</li>
  <li>Gets the app.config file and adjusts the connectionstring.</li>
  </ul></li>
  </ul>
  
  <p>Everything works well <strong>expect saving the configuration file: we recieve this error:</strong></p>
  
  <blockquote>
    <p>System.Configuration.ConfigurationErrorsException: An error occurred creating >the configuration section handler for entityFramework: Could not load file or >assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, >PublicKeyToken=b77a5c561934e089' </p>
  </blockquote>
  
  <p>Strange enough we don't get any error with entityframwork when running and debugging the main application. Also we were able to execute the code as unittest, so this assembly problem occurs only when changing the configuration file during installation with visual studio installer</p>
  
  <p>Below you can find the code to change the configuration file.</p>
  
  <pre><code>void DeployInstaller_AfterInstall(object sender, InstallEventArgs e)
  {
    try
    {
      Configuration config = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
  
      string connectionsection = config.ConnectionStrings.ConnectionStrings
      ["XBSDbDataContext"].ConnectionString;
  
      ConnectionStringSettings connectionstring = null;
      if (connectionsection != null)
      {
            config.ConnectionStrings.ConnectionStrings.Remove("XBSDbDataContext");
      }
  
      connectionstring = new ConnectionStringSettings("XBSDbDataContext", connectionString);
      config.ConnectionStrings.ConnectionStrings.Add(connectionstring);
  
      config.Save(ConfigurationSaveMode.Minimal, true);
      }
      catch (Exception ex)
      {
            MessageBox.Show(ex.ToString());      
      }
  }
  </code></pre>
  
  <p>Any idea what can be the cause and how to resolve it? Many thanks in advance.</p>
  
  <blockquote>
    <p><strong>-- UPDATE -- WE FOUND A WORK  AROUND.</strong></p>
    
    <p>By avoiding to use the ConfigurationManager class to edit the configuration
    file we no longer have this problem. This is now done with the system.xml
    namespace.</p>
  </blockquote>
  
  <pre><code>  //updating config file
    XmlDocument XmlDoc = new XmlDocument();
    MessageBox.Show(Assembly.GetExecutingAssembly().Location + ".config");
    XmlDoc.Load(Assembly.GetExecutingAssembly().Location+".config");
    foreach (XmlElement xElement in XmlDoc.DocumentElement)
    {
         if (xElement.Name == "connectionStrings")
         {
              xElement.LastChild.Attributes["connectionString"].Value = connectionString;
         }
    }
    XmlDoc.Save(Assembly.GetExecutingAssembly().Location + ".config");
  </code></pre>