【问题标题】:Castle Windsor does not work under Medium Trust温莎城堡在中等信托下不工作
【发布时间】:2012-07-30 02:25:44
【问题描述】:

尝试运行使用 Castle Windsor 的 ASP.NET MVC 应用程序时,会出现以下错误。

“/”应用程序中的服务器错误。

覆盖成员时违反了继承安全规则: 'Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()'。 覆盖方法的安全可访问性必须与 被覆盖的方法的安全可访问性。

描述:执行过程中发生了未处理的异常 当前的网络请求。请查看堆栈跟踪以获取更多信息 有关错误的信息以及它在代码中的来源。

异常详细信息:System.TypeLoadException:继承安全性 覆盖成员时违反的规则: 'Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()'。 覆盖方法的安全可访问性必须与 被覆盖的方法的安全可访问性。

来源错误:

在执行过程中产生了一个未处理的异常 当前的网络请求。有关原产地和位置的信息 可以使用下面的异常堆栈跟踪来识别异常。

堆栈跟踪:

[TypeLoadException:继承安全规则被违反,而 压倒性成员: 'Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()'。 覆盖方法的安全可访问性必须与 被覆盖的方法的安全可访问性。]
Castle.Windsor.WindsorContainer..ctor() +0

程序集Castle.Core.dllCastle.Windsor.dll 是根据github 上的源代码构建的。程序集的源代码包括文件SecurityAssemblyInfo.cs,其源代码如下:

// Sets up assembly level security settings
#if ! SILVERLIGHT
[assembly: System.Security.AllowPartiallyTrustedCallers]
#if DOTNET40
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level2)]
#endif
#endif

我已经使用ILSpy 验证了System.Security.AllowPartiallyTrustedCallers 属性已在两个文件的程序集中声明。

Web 应用程序正在使用<trust level="Medium" /> 运行。

【问题讨论】:

    标签: asp.net-mvc castle-windsor


    【解决方案1】:

    通过对 Castle.Core 进行以下更改,我能够成功构建并运行我的 mvc 应用程序:

    SecurityAssemblyInfo.cs:

    改为如下:

    [程序集:System.Security.AllowPartiallyTrustedCallers] [程序集:System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

    ProxyGenerator.cs:

    在 ProxyGenerator::ProxyGenerator(IProxyBuilder) 中更改了三行:

    if (HasSecurityPermission())
    {
        Logger = new TraceLogger("Castle.DynamicProxy", LoggerLevel.Warn);
    }
    

    变成:

    // if (HasSecurityPermission())
    // {
    //    Logger = new TraceLogger("Castle.DynamicProxy", LoggerLevel.Warn);
    // }
    

    知道这些可能会产生什么样的后果。如果熟悉 SecurityRuleSets 的人能在第一部分加入,那就太好了,@Krzysztof Koźmic 可以告诉我为什么我必须注释掉跟踪记录器。

    【讨论】:

    • 你从哪里得到源代码。我从github.com/castleproject 下载了一个版本,但甚至无法在解决方案中加载项目。它一直告诉我不兼容的版本。您能否分享您构建的更新库。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多