Fluent NHibernate 和 .NET 4 的奇怪覆盖问题 [英] Weird override problem with Fluent NHibernate and .NET 4

查看:22
本文介绍了Fluent NHibernate 和 .NET 4 的奇怪覆盖问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近提出了一个问题关于在 .NET 4 中使用 Fluent NHibernate - 我解决了这个问题,但遇到了一个新问题.

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

总结
我的主要问题(目前)是配置数据库.我正在关注 本指南,但尝试使用 SQL Server 2008 Express,因为那是我将使用什么,因此我需要学习什么.

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.

失败的代码:

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

当我尝试运行我的应用程序时,在最后一行出现以下异常 (.BuildSessionFactory()):

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

重写成员时违反了继承安全规则:'FluentNHibernate.Cfg.FluentConfigurationException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'.覆盖方法的安全可访问性必须与被覆盖方法的安全可访问性相匹配.
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.

这是什么原因造成的?

推荐答案

来自 Microsoft Connect 问题:

安全属性需要重新应用于派生自的类型其他也有安全性的类型属性.

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

也许 FluentConfigurationException 需要将 [SecurityPermission] 属性应用于其 GetObjectData() 方法.

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

否则请查看 这篇博文.

编辑:最终解决方案正在将 [SecurityCritical] 添加到 FluentConfigurationException.GetObjectData()

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

这篇关于Fluent NHibernate 和 .NET 4 的奇怪覆盖问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆