2

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?

4

2 回答 2

3

您是否尝试过删除 CodeBase 标记:http: //blogs.msdn.com/b/sqlservercompact/archive/2010/05/12/troubleshooting-problem-with-private-deployment-of-sql-server-compact-3 -5sp2-entity-dll.aspx 看起来您也应该从名称中删除 .dll。下面的配置文件可以强制 Exportsqlce40.exe 针对私有 dll 文件运行(它们必须与 .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>
于 2011-05-21T15:41:28.810 回答
1

我不认为您可以在版本号不同的情况下交换程序集而无需重新编译。

抱歉,看来我的回答还是不正确。我只知道在构建时创建的程序集清单中的静态引用。

ErikEJ 的答案对于您要执行的操作似乎是正确的。另外,我认为您不需要 assemblyIdentity 中的 *.dll。从我阅读的文档中,只有当您尝试引用远程程序集或相对于您的应用程序的另一个文件夹中的程序集时,才需要 codeBase。

如果这不起作用,您可以尝试删除 assemblyIdentity 元素的 publicKeyToken 属性或通过从 VS 命令行运行“sn –T System.Data.SqlServerCe.dll”来验证公钥。

于 2011-05-21T01:19:40.127 回答