Question

I am using ServiceStack.OrmLite 4.0.9 (with PostgreSQL, which uses Npgsql). It appears that ServiceStack requires a specific version of Npgsql (2.0.11). However, there is a significant bug in Npgsql 2.0.11 (see pull request here and StackOverflow question here). I believe the bug was fixed in Npsql 2.0.12+.

How can I use a later version of Npgsql with ServiceStack.OrmLite.PostgreSQL?

I have tried to simply replace the Npgsql 2.0.11 dll file with the latest version (2.0.14.3, at time of writing), but this causes ServiceStack.OrmLite to throw the following exception:

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 has probably been compiled against a specific version of Npgsql. Is it possible to use a different version of Npgsql? Or does anyone know when ServiceStack.OrmLite.PostgreSQL will update the version of Npsql it compiles against?

Was it helpful?

Solution

In your config file, add a binding redirect to the version of Npgsql you want to use.

  <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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top