【问题标题】:Weird override problem with Fluent NHibernate and .NET 4Fluent NHibernate 和 .NET 4 的奇怪覆盖问题
【发布时间】:2009-12-21 02:22:34
【问题描述】:

我最近 asked a question 谈到了在 .NET 4 中使用 Fluent NHibernate - 我解决了这个问题,但遇到了一个新问题。

总结
我的主要问题(目前)是配置数据库。我关注this guide,但尝试使用 SQL Server 2008 Express,因为这是我将要使用的,也是我需要学习的。

失败的代码:

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()) 收到以下异常:

覆盖成员时违反了继承安全规则:“FluentNHibernate.Cfg.FluentConfigurationException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)”。覆盖方法的安全可访问性必须与被覆盖方法的安全可访问性相匹配。

是什么原因造成的?

【问题讨论】:

标签: nhibernate fluent-nhibernate .net-4.0


【解决方案1】:

来自Microsoft Connect issue

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

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

其他查看this blog post

编辑final solution[SecurityCritical] 添加到FluentConfigurationException.GetObjectData()

【讨论】:

  • OK - 但这是在 FluentNHibernate 程序集中定义的类。我应该将此视为 FluentNHibernate 中的错误(我可以在自己的源代码副本中修复)还是我的 FNH 实现中的问题?
  • 我查看了 System.Exception 的源代码(参见下面的链接),并在我的本地副本中向 FluentConfigurationException 添加了相同的属性,但它没有帮助。现在我再次阅读了错误消息,似乎其他一些类型正在继承 FluentConfigurationException,没有正确的权限,但我不知道在哪里。来源链接:labs.developerfusion.co.uk/SourceViewer/…
  • 感谢您的更新!我查看了博客文章并按照建议进行了操作(将属性添加到AssemblyInfo.cs),但没有帮助。我会留意那个新闻组的问题 =)
  • 感谢您的信息,请参阅groups.google.com/group/fluent-nhibernate/browse_thread/thread/… 以获取修复。不确定代码何时会合并到主线中。
  • 非常感谢大家!我会尽快在 FNH 源的本地副本上尝试一下,并随时通知您。
猜你喜欢
  • 2011-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-26
  • 2012-09-04
  • 2010-11-17
  • 1970-01-01
  • 2010-10-29
相关资源
最近更新 更多