Following along with some tutorials, I have a .NET Core 2.2 project with nhibernate as the ORM. I have set up a SessionFactory class and upon running the app I get an exception:
FluentNHibernate.Cfg.FluentConfigurationException
HResult=0x80131500
Message=An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
Source=FluentNHibernate
StackTrace:
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at Domain.SessionFactory.BuildSessionFactory(String connectionString) in D:\...\Domain\SessionFactory.cs:line 46
at Domain.SessionFactory.Init(String connectionString) in D:\...\Domain\SessionFactory.cs:line 29
at Application.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in D:\...\.Application\Startup.cs:line 34
Inner Exception 1:
MissingMethodException: Method not found: 'System.Security.PermissionSet System.AppDomain.get_PermissionSet()'.
I have tried installing System.Security.Permissions, as well as System.AppDomain but no luck. I have also not found an answer in 3-ish hours searching the web. It seems to be when either of the lines AddFromAssembly
or AddFromAssemblyOf<Entity>()
are used (I don't yet understand what they're for, but when they are commented out I get no exception).
private static ISessionFactory BuildSessionFactory(string connectionString)
{
var configuration = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2012.ConnectionString(connectionString)
.ShowSql())
.Mappings(m => m.FluentMappings
.AddFromAssembly(Assembly.GetExecutingAssembly())
//.AddFromAssemblyOf<Entity>()
.Conventions.Add(
ForeignKey.EndsWith("Id"),
ConventionBuilder.Property
.When(criteria => criteria.Expect(x => x.Nullable, Is.Not.Set), x => x.Not.Nullable()))
.Conventions.Add<TableNameConvention>());
//configuration.ExposeConfiguration(c =>
// new SchemaExport(c).Execute(true, true, false));
return configuration.BuildSessionFactory();
}
Turns out I needed to install nhibernate and fluentnhibernate packages in my application project as well for some reason.
User contributions licensed under CC BY-SA 3.0