【问题标题】:"Inheritance security rules violated" when running project with Ninject.Extensions.Logging.Log4Net?使用 Ninject.Extensions.Logging.Log4Net 运行项目时“违反继承安全规则”?
【发布时间】:2013-11-20 19:12:42
【问题描述】:

我正在开发一个应用程序,其中引用了 log4netNinjectNinject.Extensions.LoggingNinject.Extensions.Logging.Log4net。当我尝试运行应用程序时,我收到一个异常:

{"Inheritance security rules violated by type: 'Ninject.Extensions.Logging.LoggerModuleBase'. Derived types must either match the security accessibility of the base type or be less accessible.":"Ninject.Extensions.Logging.LoggerModuleBase"}

我对 Ninject 和日志记录扩展完全陌生。我已经看到 several suggestions 涉及添加如下内容:

[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

但我看不出真正的问题是什么,以及为什么我需要修改发布源代码以与我的应用程序合并。因此,我假设我做错了什么。问题可能是什么?

有关更多信息,该应用程序是针对 .Net 4 而不是 .Net 4 客户端配置文件构建的,我在构建扩展程序时尝试同时针对客户端配置文件和完整的 .Net 4 框架,但都没有工作。

我正在使用提供的 .sln 文件(不是 nAnt 构建文件)构建扩展的发布版本。扩展项目可以在Github找到。

我正在运行 Visual Studio 2010。

我的内核是这样构建的:

private static StandardKernel kernel;
public static StandardKernel Kernel
{
    get
    {
        return kernel;
    }
}

public static void BuildKernel()
{
    var settings = new NinjectSettings
    {
        LoadExtensions = false
    };

    var modules = new INinjectModule[]
    {
        new MainModule(),
        new Log4NetModule()
    };

    kernel = new StandardKernel(settings, modules);
}

我的 log4net 配置相当基本,但这里是我的完整 app.Config 文件:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <log4net>
    <appender name="BasicAppender" type="log4net.Appender.FileAppender">
      <threshold value="Warn"/>
      <file value="Logs/errorlog.txt"/>
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <header value="[Basic Appender]&#13;&#10;" />
        <footer value="[Basic Appender]&#13;&#10;" />
        <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="BasicAppender" />
    </root>
  </log4net>
</configuration>

【问题讨论】:

    标签: c# .net xml ninject ninject-extensions


    【解决方案1】:

    我仍然不确定是什么导致了错误,但通过 Nuget 更新到可用的版本修复了它。 https://www.nuget.org/packages/Ninject.Extensions.Logging.Log4net/3.0.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      • 2021-05-16
      • 2018-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-29
      相关资源
      最近更新 更多