Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6689249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:29:51+00:00 2026-05-26T05:29:51+00:00

As a famous ORM we decided to user nHIbernate with asp.net mvc3. We set

  • 0

As a famous ORM we decided to user nHIbernate with asp.net mvc3. We set up our project in the following way:

  1. NHibernate Repository [contains mappings, service and repositories for nhibernate]
  2. MVC3 [this is a UI]
  3. Test MVC NHibernate [this is a test project with NUnit]

In above, [] text are written ti make clear about the layers.

Everything is working fine, means all Unit Tests are passed for mapping, insert, update, delete operations.
Unfotunately, when we are doing the same operation from our mvc3 application then it threw following error:

   "An exception occurred during configuration of persistence layer."   

Full stack-trace is as follow:

   at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\ConfigurationSchema\HibernateConfiguration.cs:line 55
   at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\ConfigurationSchema\HibernateConfiguration.cs:line 36
   at NHibernate.Cfg.Configuration.Configure(XmlReader textReader) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1511
   at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1433
   at NHibernate.Cfg.Configuration.Configure(String fileName) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1418
   at NHibernate.Cfg.Configuration.Configure() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1404
   at examplemvcapp.NHibernateRepository..ctor() in D:\example\examplemvcapp-NHExample\examplemvcapp\NHibernateRepository.cs:line 33
   at examplemvcapp_NHExample.UI.Models.CreateAppraisalModel..ctor() in D:\example\examplemvcapp-NHExample\examplemvcapp-NHExample.UI\Models\Department.cs:line 70  

Please note that all configuration settings for NHIbernate are same in MVC3 app as in Test project.

Following is the guy where we got the exception :

using (var nhr = new NHibernateRepository())
{
    this.Departments = nhr.GetAll<Departments>().Select(x => new SelectListItem 
        {
            Text = x.Departmentdescription, Value = x.Id.ToString()
        });
}

Above will bring up to following and threw an exception :

public NHibernateRepository()
{
    if (sessionFactory == null)
    {
        config = new Configuration();
        config.Configure();
        config.AddAssembly(typeof(NHibernateRepository).Assembly);
        sessionFactory = config.BuildSessionFactory();
    }
    Session = sessionFactory.OpenSession();
    transaction = Session.BeginTransaction();
    Rollback = false;
}

The above is working fine in Test project :

using (var nhr = new NHibernateRepository())
{
    var DeptList = nhr.GetAll<Departments>();
}

Following is the hibernate.cfg.xml file placed in NHibernateRepository project:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">  
  <session-factory>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Data Source=(local);Initial Catalog=myDatabaseName;Integrated Security=True</property>
    <property name="show_sql">true</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="cache.use_query_cache">false</property>
    <property name="adonet.batch_size">100</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>

  </session-factory>
</hibernate-configuration>

Apart from above this project is having all dlls required for NHibernate.

In Test project there is no special configuration settings just we add reference of Repository project and other assemblies required for this and its working fine.

The same has been maintained in MVC3 application project.

Any help in this regard is most appreciable.

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:29:51+00:00Added an answer on May 26, 2026 at 5:29 am

    Per @Michael – I am closing this thread by supplying following answer, I have found during my reasearch.

    There are two things we need to do for the proper solution;

    1. If using XML files we need to set them as Embedded in properties
    2. If not using xml files – we need to make the compiled

    To set above just select file name from solution explorere and press F4 or See property window by Right clicking on the file name and then property link.

    Thanks everyone – who answered for the above question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone know of a ASP.Net version of the famous PHP class timthumb? Just need
In many perl scripts (especially in famous CPAN distros) I find the following piece
Guys, please help me with the following problem. I have encountered the famous cannot
I am following the well famous IBM tutorial on parsing an RSS feed. I
Anybody knows how to execute this using the famous Cakephp ORM-based 'find' query function?
I'm learning MVC3 by covering the famous MusicStore tutorial http://mvcmusicstore.codeplex.com/ The connection string used
Are there any named/famous/particularly good algorithms for organizing email messages into threads? I'm looking
According to the (in)famous iPhone Developer Program License Agreement change 3.3.1 — Applications may
Erlang with mnesia/dets is famous for it slow startup times after a crash. Basically
I am currently working through the famous Cocoa Programming for OSX by Aaron Hillegaas.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.