views:

1071

answers:

1

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?

+4  A: 

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()

Mauricio Scheffer
OK - but this is a class defined in the FluentNHibernate assembly. Should I take this as a bug in FluentNHibernate (that I can fix in my own copy of the source) or as a problem in my implementation of FNH?
Tomas Lycken
Tomas Lycken
Thanks for the update! I looked in the blog post and did what it suggested (added the attribute to `AssemblyInfo.cs`) but it didn't help. I'll keep an eye on that news group question =)
Tomas Lycken
Thanks for the info, see http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/ae4013d711d2e4ad for the fix. Not sure when the code will be merged into the main line.
KeeperOfTheSoul
Thanks a lot guys! I will try this out as soon as I can on my local copy of the FNH source and keep you posted.
Tomas Lycken