how to deploy npgsql on Raspberry pi 2 (Mono 4 + A

2019-08-14 17:47发布

I use Visual studio 2013 (Windows) to build a small .NET 4.5 application using Npgsql and Entity Framework 6.

On windows it just works fine. But on Raspbian, the app crash saying it cannot find npgsql provider.

   Unhandled Exception:
System.Configuration.ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider 'Npgsql'.
  at System.Data.Common.DbProviderFactories.GetFactory (System.String providerInvariantName) [0x00000] in <filename unknown>:0
[...]

On my raspberry pi 2.

I have manually installed Mono v4.0.2

I have copied my app including:

npgsql.dll v2.2.5.0

npgsql.entityframework same version

mono.security v4.0.2

and my app.config contains :

  <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <providers>
            <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="minitestEntities" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=Npgsql;provider connection string=&quot;PORT=5432;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;COMPATIBLE=2.2.5.0;DATABASE=minitest;HOST=10.0.0.1;INTEGRATED SECURITY=True;PASSWORD=azerty;USER ID=theuser&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

So i'm wondering if npgsql librairies are correctly loaded, or a if a reference is missing.

I found no docs on how to use npgsql on recent mono + ARM environment. Any info about this would be really appreciated.

1条回答
小情绪 Triste *
2楼-- · 2019-08-14 17:59

ok i found the solution in an other discution. In the meanwhile i forgot to note its URL so here the answer :

We have to add manually the provider description into app.config :

<system.data>
  <DbProviderFactories>
    <add name="Npgsql Data Provider" 
         invariant="Npgsql" 
         support="FF" 
         description=".Net Framework Data Provider for Postgresql Server" 
         type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
  </DbProviderFactories>
</system.data>

The version and PuclicKeyToken MUST match with npgsql.dll. To get the public key token, you can run that code :

typeof(Npgsql.NpgsqlFactory).AssemblyQualifiedName

Now i have no idea why this step is not necessary into windows, but a have to do into linux...

查看更多
登录 后发表回答