The type initializer for "NHibernate.Cfg.Configuration" threw an exception

After upgrading from nhibernate 1.0.4.0 to nhibernate 3.3 im, the following error occurs when trying to run "Configuration cfg = new Configuration ();"

System.TypeInitializationException was caught
  Message="The type initializer for 'NHibernate.Cfg.Configuration' threw an exception."
  Source="NHibernate"
  TypeName="NHibernate.Cfg.Configuration"
  StackTrace:
       at NHibernate.Cfg.Configuration..ctor()
       at KEH.Web.Data.NHibernateUtil..cctor() in F:\Projects\KEH nHibernate\KEHWeb\Data\Data\NHibernateUtil.cs:line 24
  InnerException: System.NotSupportedException
       Message="The invoked member is not supported in a dynamic assembly."
       Source="mscorlib"
       StackTrace:
            at System.Reflection.Emit.AssemblyBuilder.get_Location()
            at log4net.Util.SystemInfo.AssemblyLocationInfo(Assembly myAssembly)
            at log4net.Core.DefaultRepositorySelector.GetInfoForAssembly(Assembly assembly, String& repositoryName, Type& repositoryType)
            at log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly repositoryAssembly, Type repositoryType, String repositoryName, Boolean readAssemblyAttributes)
            at log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly repositoryAssembly, Type repositoryType)
            at log4net.Core.DefaultRepositorySelector.GetRepository(Assembly repositoryAssembly)
            at log4net.Core.LoggerManager.GetLogger(Assembly repositoryAssembly, String name)
            at log4net.LogManager.GetLogger(Assembly repositoryAssembly, String name)
            at log4net.LogManager.GetLogger(Type type)
            at lambda_method(ExecutionScope , Type )
            at NHibernate.Log4NetLoggerFactory.LoggerFor(Type type)
            at NHibernate.LoggerProvider.LoggerFor(Type type)
            at NHibernate.Cfg.Configuration..cctor()
       InnerException: 

Any help would be greatly appreciated.

The code for the NHibernateUtil class is as follows:

public class NHibernateUtil
    {
        private static readonly Configuration cfg;
        private static readonly ISessionFactory sessionFactory;
        private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        static NHibernateUtil()
        {
            try
            {
                logger.Debug("Before Initializing NHibernate");
                cfg  = new Configuration();
                cfg.AddAssembly("KEH.Web.Data");
                sessionFactory = cfg.BuildSessionFactory();
                logger.Debug("Initialized NHibernate");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        public static ISession OpenSession()
        {
            logger.Debug("Before Getting Connection");
            return sessionFactory.OpenSession();
        }
}
+3
source share
3 answers

I had the same problem. In fact, I used a library that used the old version of log4net. NHibernate tries to use it if it finds one. Therefore, I had to force it to use (or not actually use) another registrar by adding this line: LoggerProvider.SetLoggersFactory (new NoLoggingLoggerFactory ());

+4
source

, ,

cfg.AddAssembly("KEH.Web.Data");

cfg.AddAssembly(typeof(Entity).Assembly);

Entity - , .

+1

, Google:

. , ( ). IIS . , HTML JPG, , - w3wp.exe . IIS, , NHibernate iisreset. .

, NHibernate, , -. "", , , , . , , , , IIS, , - .

, HTML JPG , , 100%.

, -.

-2

All Articles