title: app.config for WinForm .NET 4 to Private Deploy SQL Server CE SP2
body: <p>My Visual Studio 2010 (C#) application is working, and I've been trying to deploy it using a Setup Project all this week with no success.</p>
  
  <p>I started by following Steve Lasker's Web Blog on <a href="http://blogs.msdn.com/b/stevelasker/archive/2008/10/22/privately-deploying-sql-server-compact-with-the-ado-net-entity-provider.aspx" rel="nofollow">Privately Deploying SQL Server Compact with the ADO.NET Entity Provider</a>. It had me modify the project's <code>app.config</code> file to include the following:</p>
  
  <pre><code>  &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
        &lt;remove invariant="System.Data.SqlServerCe.3.5"&gt;&lt;/remove&gt;
        &lt;add name="Microsoft SQL Server Compact Data Provider"
             invariant="System.Data.SqlServerCe.3.5"
             description=".NET Framework Data Provider for Microsoft SQL Server Compact"
             type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.50, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/&gt;
      &lt;/DbProviderFactories&gt;  
    &lt;/system.data&gt;
  </code></pre>
  
  <p>That installation only ran successfully on PCs where SQL Server CE was already installed (like <strong>MY</strong> PC only).</p>
  
  <p>I got to looking closer at the article, and noticed it was written in 2008, but that a David V left a comment linking to the <em><a href="http://social.msdn.microsoft.com/profile/sql%20ce%20team/" rel="nofollow">SQL CE Team</a></em>'s article <a href="http://blogs.msdn.com/b/sqlservercompact/archive/2010/05/12/troubleshooting-problem-with-private-deployment-of-sql-server-compact-3-5sp2-entity-dll.aspx" rel="nofollow">Troubleshooting: Privately deploying the SQL Server Compact 3.5 SP2 ADO.NET Entity Framework provider (System.Data.SqlServerCe.Entity.dll) in the application folder does not work</a>. In their article, they said I had to add "assembly binding redirection" (bad link) and append my <code>app.config</code> file with the following information:</p>
  
  <pre><code>  &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral"/&gt;
          &lt;bindingRedirect oldVersion="3.5.1.0-3.5.1.50" newVersion="3.5.1.50"/&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
  </code></pre>
  
  <p>So, here I am with an Installer that does not install.</p>
  
  <pre><code>  &lt;?xml version="1.0"?&gt;
    &lt;configuration&gt;
      &lt;appSettings&gt;
        &lt;add key="LastRun" value=""/&gt;
        &lt;add key="UserName" value=""/&gt;
      &lt;/appSettings&gt;
      &lt;startup useLegacyV2RuntimeActivationPolicy="true"&gt;
        &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/&gt;
      &lt;/startup&gt;
      &lt;system.data&gt;
        &lt;DbProviderFactories&gt;
          &lt;remove invariant="System.Data.SqlServerCe.3.5"&gt;&lt;/remove&gt;
          &lt;add name="Microsoft SQL Server Compact Data Provider"
               invariant="System.Data.SqlServerCe.3.5"
               description=".NET Framework Data Provider for Microsoft SQL Server Compact"
               type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.50, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/&gt;
        &lt;/DbProviderFactories&gt;  
      &lt;/system.data&gt;
      &lt;runtime&gt;
        &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
          &lt;dependentAssembly&gt;
            &lt;assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral"/&gt;
            &lt;bindingRedirect oldVersion="3.5.1.0-3.5.1.50" newVersion="3.5.1.50"/&gt;
          &lt;/dependentAssembly&gt;
        &lt;/assemblyBinding&gt;
      &lt;/runtime&gt;
    &lt;/configuration&gt;
  </code></pre>
  
  <p>Is my <code>app.config</code> file corrupt?</p>
  
  <p>My application still runs just fine, but the Installer fails to install anything. The Installer's error is always 2727 for a temporary file name that changes:</p>
  
  <blockquote>
    <p>DEBUG: Error 2727:  The directory entry '_1083472CD2EB47548297E3336FCD9A58' does not exist in the Directory table</p>
  </blockquote>
  
  <p>What should I do about this?</p>
  
  <p>Has anyone successfully deployed a Microsoft SQL CE Server SP2 for a Private instance?</p>