Fluent NHibernate 和 .NET 4 的奇怪覆盖问题
我最近问了一个关于使用 Fluent 的问题 NHibernate with .NET 4 - 我解决了这个问题,但遇到了一个新问题。
总结
我的主要问题(目前)是配置数据库。我正在遵循本指南,但尝试针对 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)'。重写方法的安全可访问性必须与被重写方法的安全可访问性相匹配。
是什么原因造成的?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 Microsoft Connect 问题:
也许
FluentConfigurationException
需要将[SecurityPermission]
属性应用于其GetObjectData()
方法。否则请查看
编辑:最终解决方案添加了<代码>[SecurityCritical] 到 <代码>FluentConfigurationException.GetObjectData()
From the Microsoft Connect issue:
Maybe
FluentConfigurationException
needs to apply a[SecurityPermission]
attribute to itsGetObjectData()
method.Else check out this blog post.
EDIT: The final solution was adding
[SecurityCritical]
toFluentConfigurationException.GetObjectData()