Hi,
I'm using Fluent NHibernate in my ASP.Net project. While on my machine everything works fine, when I publish my project to my hosting server, I'm having some issues.
Below is the code that I'm using:
try
{
var db = MsSqlConfiguration.MsSql2008.ConnectionString(_connStr);
_sessionFactory = Fluently.Configure()
.Database(db)
.Mappings(c => c.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly()))
.ExposeConfiguration(c => c.SetProperty("hbm2dll.keywords", "auto-quote"))
.BuildSessionFactory();
}
catch (Exception ex)
{
_log.Error("Error during session factory initialization. Error message: " + ex.Message);
_log.Error("Full Error Details: " + ex.ToString());
return false;
}
When I'm running the above code on the hosting server, I'm getting the following error:
01/12/2015 12:07:35:585 - ERROR: Error during session factory initialization. Error message: Inheritance security rules violated while overriding member: 'FluentNHibernate.Cfg.FluentConfigurationException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
01/12/2015 12:07:35:585 - ERROR: Full Error Details: System.TypeLoadException: Inheritance security rules violated while overriding member: 'FluentNHibernate.Cfg.FluentConfigurationException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at NIPDBHandler.CDataAccessLayer.Init() in CDataAccessLayer.cs:line 32
Now I know that there was a known issue in Fluent NHiberate in the method "FluentNHibernate.Cfg.FluentConfigurationException.GetObjectData" in .NET 4.0. Basically, the problem was that the mentioned method was not decorated with the attribute "[SecurityCritical]". I am 100% sure that the said method is decorated with the said attribute. I'm using FluentNHibernate version 2.0.1.0 and I used ILSpy to check that the method is really decorated and, in fact, it was decorated with the "[SecurityCritical]" attribute.
I've also tried adding the following line to the assembly file of FluentNHibernate and recompiled everything.
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
This time, the only difference that I saw was that the configuration was taking a long time to complete, resulting in ThreadBeingAborted exception from the .aspx page.
Any help would be greatly appreciated because I honestly don't know what I'm doing wrong.
Thanks in advance!