Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird override problem with Fluent NHibernate and .NET 4

I recently asked a question about using Fluent NHibernate with .NET 4 - I solved that problem, but met a new one.

Summary
My main problem (at the moment) is configuring the database. I'm following this guide, but trying to work against SQL Server 2008 Express instead, as that's what I'll be using and thus what I need to learn.

The failing code:

public static ISessionFactory CreateSessionFactory()
{
    return Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("mssql")))
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>())
        .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true))
        .BuildSessionFactory();
}

When I try to run my application, I get the following exception on the last line (.BuildSessionFactory()):

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.

What is causing this?

like image 779
Tomas Aschan Avatar asked Feb 27 '23 22:02

Tomas Aschan


1 Answers

From the Microsoft Connect issue:

Security attributes need to be re-applied on types that derive from other types that also have security attributes.

Maybe FluentConfigurationException needs to apply a [SecurityPermission] attribute to its GetObjectData() method.

Else check out this blog post.

EDIT: The final solution was adding [SecurityCritical] to FluentConfigurationException.GetObjectData()

like image 190
Mauricio Scheffer Avatar answered Mar 03 '23 17:03

Mauricio Scheffer