Question

My application references a library project that has System.Data.SqlServerCe 4.0.0.0 as a dependency.

I'm trying to private deploy my app, however, which requires System.Data.SqlServerCe 4.0.0.1.

So, I set up my app so that System.Data.SqlServerCe 4.0.0.1 gets copied into the output directory (into the same folder as the executable), and I added an assemblyBinding to my App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  ...
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity
          name="System.Data.SqlServerCe.dll"
          publicKeyToken="89845dcd8080cc91" />
        <bindingRedirect oldVersion="4.0.0.0" newVersion="4.0.0.1" />
        <codeBase version="4.0.0.1" href="System.Data.SqlServerCe.dll" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Unfortunately, I'm getting this error:

Could not load file or assembly 'System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0X80131040)

Question

Is it possible to swap System.Data.SqlServerCe 4.0.0.0 with version 4.0.0.1 at runtime to allow for private deployment?

Was it helpful?

Solution

Have you tried to remove the CodeBase tag: http://blogs.msdn.com/b/sqlservercompact/archive/2010/05/12/troubleshooting-problem-with-private-deployment-of-sql-server-compact-3-5sp2-entity-dll.aspx It looks like you should remove .dll from the name as well. The config file below can force Exportsqlce40.exe to run against the private dll files (they must then be present in the same folder as the .exe):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" />
        <bindingRedirect oldVersion="4.0.0.0" newVersion="4.0.0.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

OTHER TIPS

I don't think you can swap assemblies when their version numbers are different without a recompilation.

Sorry, it looks like my answer was incorrect anyway. I was only aware of the static references in the assemblies manifest created at build time.

ErikEJ's answer appears correct for what you are looking to do. Also I don't think you need the *.dll in assemblyIdentity. From the documentation I read, codeBase is only needed if you are trying to reference a remote assembly or an assembly in another folder relative to your application.

If that doesn't work, you can try removing the publicKeyToken attribute for the assemblyIdentity element or verify the public key by running "sn –T System.Data.SqlServerCe.dll" from the VS command line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top