NHibernate / Npgsql throws an exception during CreateSchema while debugging UnitTest

I have two C # projects, Model and ModelTest. The model consists of ActiveRecord objects (wrapper around Hibernate). In ModelTest, I created a simple unit test:

[TestClass] public class UnitTest1 { [TestInitialize] public void Init() { Model.Init(); Model.CreateSchema(); } [TestMethod] public void TestMethod1() { } } 

Model.Init () registers all types of model assembly using ActiveRecord. Model.CreateSchema () wraps ActiveRecordStarter.CreateSchema (), which calls CreateSchema () NHibernate.

This code works fine if I run the unit test, but it fails if I "debug" the unit test. In debug mode, an exception is thrown in CreateSchema ():

 NpgsqlException: 'ERROR: 42P01: table "user" does not exist' 

The exception appears to be during a SQL call to "drop table user cascade", which obviously does not work if the database is empty before running the test. I assume that the crash is always sent before creating a new table.

Does Npgsql work in debug mode with respect to the result of a drop request?

+4
source share
1 answer

I had the same problem as Tarnschaf - SchemaUpdate.Create(...) , and the offensive sql was drop table "tablename" cascade , resulting in the above-mentioned error "table does not exist".

It turns out that in one of the projects there was a link to an assembly related to Nhibernate, which was no longer in the same place. I am not sure why this did not appear when the solution was cleared and rebuilt. Removing all the links from the project and adding them again solves the problem (for me).

Just post it if it helps someone else along the way. The Nhibernate exception was less useful.

+1
source

All Articles