0

I have the following structure in Visual Studio

Control (Solution)
  AppDB (Project)
    Classes (Folder)
       Piece.cs
    Mapping (Folder)
       PieceMap.cs

I add the assembly map at runtime doing the following instructions

Configuration hibernateConfiguration = new Configuration();
hibernateConfiguration.SetProperty("connection.connection_string", "server=(local);Data Source="+pRutaDB);
hibernateConfiguration.AddAssembly("AppDB.Mapping.PieceMap");
hibernateConfiguration = hibernateConfiguration.Configure();
NHibernate.ISessionFactory sessionFactory = hibernateConfiguration.BuildSessionFactory();
NHibernate.ISession session = sessionFactory.OpenSession();
NHibernate.ITransaction tr = session.BeginTransaction();
Piece p = new Piece();
p.name = "Test Piece";
pSession.SaveOrUpdate(p);
tr.Commit();

But when the tr.Commit() instruction arrives, thew following error shows up

Error: NHibernate.MappingException: Could not add assembly AppDb.Mapping.PieceMap ---> System.IO.FileNotFoundException

Anyone can tell me how to add the assembly at runtime?

Thanks!

Edit: with the instruction the error changed hibernateConfiguration.AddAssembly(typeof(GeometriaDB.Mapping.PieceMap).Assembly);

Now the following error appears:

NHibernate.MappingException: No persister for: GeometriaDB.Clases.Proyecto

So now why is that error appearing?

a.ras2002
  • 385
  • 2
  • 7
  • 21

1 Answers1

0

At least you should add .dll to assembly name:

hibernateConfiguration.AddAssembly("AppDB.Mapping.PieceMap.dll");

And also dll should be in same directory or you should show full path to assembly.

Another way you can use is:

hibernateConfiguration.AddAssembly(typeof(AppDB.Mapping.PieceMap.<and any class name>).Assembly);