How should I be using Npgsql in Appharbor?

2

I've developed a quick and simple app on my local machine using SQLite to get started. Now that I'm in the middle of working out how to upload to AppHarbor, I'm a bit stuck on getting the link to ElephantSQL to work.

I used the Application PostgreSQL Sample Application to determine that I needed to use the PostgreSQLConfiguration class for my FluentNHibernate configuration and install the Npgsql package to my solution (I got version 2.0.12.1).

When I push the code up to AppHarbor, it builds and deploys happily. When the server starts to spin up the AppDomain, it throws the error Could not load file or assembly 'policy.2.0.Npgsql' or one of its dependencies. Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043). This isn't logged in the Errors section of the AppHarbor dashboard (perhaps this is a missing feature or a bug?) so I had to turn off CustomErrors to figure out what was going on.

What have I missed?

Additional - I tried downgrading to package version 2.0.11. This did not include the policy.2.0.Npgsql.dll file and when trying to load the app, it fails with the error Unable to find the requested .Net Framework Data Provider. It may not be installed..

c#
nhibernate
appharbor
npgsql
asked on Stack Overflow Jan 14, 2013 by Simon Gill • edited Jan 15, 2013 by Simon Gill

3 Answers

2

I got it working by going down to version 2.0.11 and made sure that the DbProviderFactories configuration section had the correct version number in the type attribute.

<DbProviderFactories>
  <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Framework Data Provider for PostgreSQL Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.11.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
</DbProviderFactories>
answered on Stack Overflow Jan 15, 2013 by Simon Gill
1

I was running npgsql 2.0.13 beta (December 2013) on AppHarbor and was getting hosed by this issue for a little while, till I discovered that it's not needed if you're running the latest assembly and don't care about bindingRedirects - it's a dll generated by the .net AL.exe/assembly linker tool to roll up the contents of the policy.2.0.Npgsql.config file (check out https://github.com/npgsql/Npgsql/blob/master/src/policyFileBuild.bat to see how that's compiled).

MY CONFIGURATION:
VS2012
.net 4.5
MVC4
Entity Framework 6 (installed via nuget package restore)
npgsql - 2.0.13.91 (installed via nuget package restore)

THE HACKY FIX:
By Deleting it from the build as a post build event (Project Menu --> Properties --> Build Events --> Post Event Command Line), you can bypass the error (which I don't know why doesn't work on AppHarbor).

So add this nonsense:

del $(TargetDir)policy.2.0.Npgsql.dll /F
del $(TargetDir)policy.2.0.Npgsql.config /F
dir $(TargetDir)

del $(TargetDir)_PublishedWebsites\<appname/>\bin\policy.2.0.Npgsql.dll
del $(TargetDir)_PublishedWebsites\<appname/>\bin\policy.2.0.Npgsql.config
dir $(TargetDir)_PublishedWebsites\<appname/>\bin\

This is probably over-kill, but note that the dir dos command statement gives you feedback on the contents of your directories to make sure the files have actually been deleted. This is viewable from Show Log of build activities in AppHarbor.

Regarding the 2 sets of deletes on dll and config from that god awful msbuild packaging routine (/output directory and the /output/_PublishedWebsites) - IMHO - it's better to be thorough if you're killing stuff, but it may be sufficient to simply delete only from _publishedwebsites...

When it gets built in AppHarbor, this will chuck it from the targeted deployment. You might have to wait for a few minutes for the deploy to complete, but it's absence from the deploy will unblock you.

answered on Stack Overflow Dec 6, 2013 by Eyeless Whim • edited Dec 6, 2013 by Eyeless Whim
0

I think this nuget package is missing the policy.2.0.Npgsql.dll file. Can you install the package for 2.0.12 version from official nuget Npgsql package? It has the missing file.

I hope it helps.

answered on Stack Overflow Jan 15, 2013 by Francisco Junior

User contributions licensed under CC BY-SA 3.0