我在 .NET 4.5.1 上使用 c# ASP.NET 应用程序的发布模式下从 Nhibernate 4.1.0 收到此错误:
Inheritance security rules violated while overriding member: 'Antlr.Runtime.RecognitionException.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.
作为 Antl3 一个包含的 dll,我无法弄清楚问题是什么
这篇 stackoverflow 帖子为我指明了正确的方向。
我需要有一个Antl3版本,其中GetObjectData标记为SecurityCriticalAttribute,这显然不是NHibernate 4.1.0源代码附带的版本,所以我从这里获得了Antl3源代码,并在Antl3.Runtime.net40-client下查看了RecognitionException,并看到它是正确的:
[SecurityCritical]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
所以我已经破坏了它,替换了 NHibernate-4.1.0.GA-src\libet 文件夹中生成的 dll,等等,现在应用程序运行良好,现在应用程序运行良好
这很可能是因为您的应用程序需要"更多信任"。您可以通过在web.config
中添加<trust level="Full" />
(system.web
内)来更改应用程序的信任级别。
<system.web>
<trust level="Full" />
<system.web>
有关 ASP.NET 信任级别的更多信息,请参阅此处。