0

Just some background: it was working code in Production since 2013. Recently added DB password encrypt/decrypt logic in code - compiled code using VS2010 - it's working fine in test but not in Production.

I am assuming it has something to do with configuration xml , mapping or some mismatch of NHibernate dll. Not sure if build/output folders need some thing?

Error in Production:

FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
NHibernate MappingException: Could not compile the mapping document: (XmlDocument) ---> System.InvalidCastException: [A]NHibernate.Cfg.MappingSchema.HbmMapping cannot be cast to [B]NHibernate.Cfg.MappingSchema.HbmMapping. Type A originates from 'NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\drcwm\bb04bdb4\da32eda4\assembly\dl3\bb71f3c5\00f7c13c_ef33d101\NHibernate.dll'. Type B originates from 'NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' in the context 'LoadFrom' at location 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\drcwm\bb04bdb4\da32eda4\assembly\dl3\44ab434f\00f7c13c_ef33d101\NHibernate.dll'.
at NHibernate.Cfg.XmlHbmBinding.Binder.Deserialize[T](XmlNode node)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node)
at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
--- End of inner exception stack trace ---
at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc, String name)
at FluentNHibernate.PersistenceModel.Configure(Configuration cfg)
at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(Configuration cfg)
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at DB.FIOS_SOUTH.DataBase.get_SessionFactory()
NLog.LoggerImpl.Write Error "System.NullReferenceException: Object reference not set to an instance of an object.
at DB.Base.DataBase.get_Session()
at DB.Base.DataBase.Query[T]()
at RemoteService.BaseListService.FilteredQuery[T](BaseParameter parameter, DataBase db, Boolean applyPagination, Boolean applySortOrder)
at RemoteService.JobsListService.GetJobsWithChildrenCount[T](JobParameter parameter)

Code throwing exception is below:

if (_ISessionFactory == null)
{
    try
    {
        _ISessionFactory = Fluently.Configure()
                            .Database(MsSqlConfiguration.MsSql2005
                            .ConnectionString(ConnectionString).IsolationLevel(IsolationLevel.ReadUncommitted)
                            .Cache(c => c.ProviderClass<HashtableCacheProvider>())
                            )
                            .Mappings(m =>
                            {
                                m.HbmMappings
                                .AddFromAssemblyOf<FIOS_NORTH_QUEUES.DataBase>();
                                m.FluentMappings
                                .AddFromNamespaceOf<FIOS_NORTH_QUEUES.Map.QueueWFADOItemMap>();
                            })
                            .ExposeConfiguration(ModifyConfiguration)
                            .BuildSessionFactory();
    }
    catch (Exception ex)
    {
        logger.Error(ex);
    }
}
kayess
  • 3,384
  • 9
  • 28
  • 45
Naj
  • 13
  • 1
  • 5

1 Answers1

0

your production process has already loaded NHibernate from an old (shadow-)cache location then the new dlls are loaded from a new location and try to load their dependencies next to them, but since the process already loaded the assemblies from elsewhere it has a conflict.

You have to try unloading/restarting the AppDomain by restarting the server process, asp.net process, iis, whatever. The error is not related to the code at all.

Firo
  • 30,626
  • 4
  • 55
  • 94