【发布时间】:2013-11-20 19:12:42
【问题描述】:
我正在开发一个应用程序,其中引用了 log4net、Ninject、Ninject.Extensions.Logging 和 Ninject.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] " />
<footer value="[Basic Appender] " />
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] <%property{auth}> - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="BasicAppender" />
</root>
</log4net>
</configuration>
【问题讨论】:
标签: c# .net xml ninject ninject-extensions