使用最新版本的Npgsql和ServiceStack.OrmLite.PostgreSQL

时间:2014-02-07 05:59:32

标签: servicestack ormlite-servicestack npgsql

我正在使用ServiceStack.OrmLite 4.0.9(使用PostgreSQL,它使用Npgsql)。似乎ServiceStack需要特定版本的Npgsql(2.0.11)。但是,Npgsql 2.0.11中存在重大错误(请参阅pull request here和StackOverflow问题here)。我相信这个bug已在Npsql 2.0.12 +中修复。

如何在ServiceStack.OrmLite.PostgreSQL中使用更高版本的Npgsql?

我试图用最新版本(编写本文时为2.0.14.3)简单地替换Npgsql 2.0.11 dll文件,但这会导致ServiceStack.OrmLite抛出以下异常:

System.IO.FileLoadException was unhandled by user code
  HResult=-2146234304
  Message=Could not load file or assembly 'Npgsql, Version=2.0.11.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  Source=ServiceStack.OrmLite.PostgreSQL
  FileName=Npgsql, Version=2.0.11.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
  FusionLog=Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll

  StackTrace:
       at ServiceStack.OrmLite.PostgreSQL.PostgreSQLDialectProvider.CreateConnection(String connectionString, Dictionary`2 options)
       at ServiceStack.OrmLite.OrmLiteConfig.ToDbConnection(String dbConnectionStringOrFilePath, IOrmLiteDialectProvider dialectProvider)
       at ServiceStack.OrmLite.OrmLiteConnection.get_DbConnection()
       at ServiceStack.OrmLite.OrmLiteConnection.Open()
       at ServiceStack.OrmLite.OrmLiteConnectionFactory.OpenDbConnection()
       at ServiceStack.Service.get_Db()
       at XYZ.Post(Abc req) in XYZ.cs:line 45
       at lambda_method(Closure , Object , Object )
       at ServiceStack.Host.ServiceRunner`1.Execute(IRequest request, Object instance, TRequest requestDto)

ServiceStack.OrmLite.PostgreSQL可能是针对特定版本的Npgsql编译的。是否可以使用不同版本的Npgsql?或者有人知道ServiceStack.OrmLite.PostgreSQL何时会更新它编译的Npsql版本?

1 个答案:

答案 0 :(得分:2)

在配置文件中,将绑定重定向添加到要使用的Npgsql版本。

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.14.2" newVersion="2.0.14.2" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>