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

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

问题描述

我最近问了一个问题有关使用功能NHibernate使用.NET 4 - 我解决了这个问题,但遇到了一个新的

摘要
我的主要问题(目前)的配置数据库。我下面本指南,但努力工作,对SQL Server 2008防爆preSS代替,因为这是我将使用,因此我需要学习的。

失败的code:

 公共静态ISessionFactory CreateSessionFactory()
{
    返回Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2008.ConnectionString(C => c.FromConnectionStringWithKey(MSSQL)))
        .Mappings(M => m.FluentMappings.AddFromAssemblyOf<程序>())
        .ExposeConfiguration(CFG =>新建的SchemaExport(CFG).Create(真,真))
        .BuildSessionFactory();
}
 

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

而覆盖件
继承安全规则违反: 'FluentNHibernate.Cfg.FluentConfigurationException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)。压倒一切的方法必须与方法的安全辅助功能相匹配的安全访问被覆盖。

是什么原因造成的?

解决方案

在<一个href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=464751">Microsoft连接问题:

  

安全属性需   重新施加在从派生类型   其他类型也具有安全   属性。

也许<一href="http://github.com/jagregory/fluent-nhibernate/blob/master/src/FluentNHibernate/Cfg/FluentConfigurationException.cs"><$c$c>FluentConfigurationException需要一个 [性SecurityPermission] 属性应用到它的 GetObjectData使用()方法。

否则签出<一href="http://weblogs.asp.net/peterblum/archive/2009/11/06/typeloadexception-based-on-security-transparent-$c$c-level-2.aspx">this博客文章。

修改:被添加最终的解决方案 [SecurityCritical] 到<一个href="http://github.com/jagregory/fluent-nhibernate/blob/master/src/FluentNHibernate/Cfg/FluentConfigurationException.cs"><$c$c>FluentConfigurationException.GetObjectData()

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?

解决方案

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

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

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