log4net报错Could not load type 'System.Security.Claims.ClaimsIdentity'
使用log4net,在win7上可以正常使用,在xp电脑上可以生成access数据库,但是无法写数据到mdb文件,即mdb始终是空白的
排除了程序原因,怀疑是xp缺少什么dll之类的
偶然查到log4net的调试方法:
第1步:
(1)如果是配置在app.confing等confing文件中,在appSettings节点中增加名称为“log4net.Internal.Debug”的节点,并确保值为“true"
<configuration>
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
</configuration>
(2)如果配置在自定义的confing中,通过代码自定义调用,则直接在log4net节点增加debug="true"
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections> <log4net debug="true">
<appender name="AllRollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
......
</appender>
</log4net>
</configuration>
第2步:在app.config文件<configuration>节点内增加如下节点
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\tmp\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>
注意:文件夹 C:\tmp 必须存在,否则无法创建文件
另外我在自定义并且加了watch的的config文件中加这段无效,不清楚是什么原因
或者用代码添加
System.Diagnostics.Trace.Listeners.Clear();
System.Diagnostics.Trace.Listeners.Add(
new System.Diagnostics.TextWriterTraceListener("C\tmp\log4net.txt"));
加入了log4net的内部调试功能后,再运行程序调用log4net写日志时,会在C:\tmp\log4net.txt文件中显示出如下错误信息:
log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Failed in DoAppend
System.TypeLoadException: Could not load type 'System.Security.Claims.ClaimsIdentity' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at log4net.Core.LoggingEvent.get_UserName()
at log4net.Core.LoggingEvent.FixVolatileData(FixFlags flags)
at log4net.Appender.BufferingAppenderSkeleton.Append(LoggingEvent loggingEvent)
at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)
简单的理解是找不到类System.Security.Claims.ClaimsIdentity,查了下msdn,这个类属于.net 4.5
在网上搜了许久没找到解决方法,都大同小异,跟log4net官方说法类似 让别用xp,或者安装.net framework 4.5
但是现在国内很多地方为了节约成本等原因还是在用xp,而xp最高只能安装.net 4.0,显然无法解决
我试过安装.net framework 4.0的补丁,KB2468871、KB2861188、KB2789642、KB2898855、KB2901110,结果无效
试过360修复所有漏洞,按推荐的打了所有补丁,也不行
通过网上的帖子了解到,问题引入的原因可能是,我使用了在.net 4.5的环境中生成的log4net.dll
于是顺着这个思路,我最终也找到解决方案:
在官网下载源码log4net-2.0.8-src.zip,解压后用vs2010打开log4net-2.0.8-src\log4net-2.0.8\src下的log4net.vs2010.sln

源码下有两个项目,直接生成解决方案会报错,发现是 log4net.Tests.vs2010下的nunit.framework引用丢失了

直接在log4net.Tests.vs2010上右键,卸载项目,再重新生成就好了

最后将log4net-2.0.8-src\log4net-2.0.8\build\bin\net\4.0\debug目录下重新生成的dll引入到我们的工程就好了
简单测试了一下可以使用,问题解决。附上文件log4net.dll (2.0.8 .net framework 4.0)
log4net报错Could not load type 'System.Security.Claims.ClaimsIdentity'的更多相关文章
- Unable to find a constructor to use for type System.Security.Claims.Claim. A class should either have a default constructor
Newtonsoft.Json DeserializeObject 反序列化 IdentityServer4.Models Cliecnt 错误: Newtonsoft.Json.JsonSeria ...
- Atom打开报错:"Cannot load the system dictionary for zh-CN"
1. 问题描述 最近每次使用atom打开文件,总是报错"Cannot load the system dictionary for zh-CN" 2. 解决方法 File --&g ...
- Could not load type 'System.Reflection.AssemblySignatureKeyAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c
错误: Could not load type 'System.Reflection.AssemblySignatureKeyAttribute' from assembly 'mscorlib, V ...
- 备库搭建后,进入备库报错psql: FATAL: the database system is starting up
备库搭建后,进入备库报错psql: FATAL: the database system is starting up 原因:备库配置文件没有hot_standby = on mast ...
- 报错: Access restriction: The type JPEGImageEncoder is not accessible due to restriction on required library
报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...
- junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题
junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题,说明代码是没问题的,配置也没问题.开始时怀疑是我使用junit版本 ...
- Linux mount挂载磁盘报错 mount: wrong fs type, bad option, bad superblock on /dev/vdb
Linux mount挂载磁盘报错 mount: wrong fs type, bad option, bad superblock on /dev/vdb Linux挂载磁盘报如下错误: moun ...
- Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, ...
- Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute'
[TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from as ...
随机推荐
- install cinnamon on ubuntu 14.04
emotion: I feel not comfortable with ubuntu 14.04 default desktop unity,i still look for a alternati ...
- layui.code代码装饰器
<!doctype html><html lang="en"><head> <meta charset="UTF-8" ...
- iOS学习笔记27-摄像头
一.摄像头 在iOS中,手机摄像头的使用有以下两种方法: UIImagePickerController拍照和视频录制 优点:使用方便,功能强大 缺点:高度封装性,无法实现一些自定义工作 AVFoun ...
- BZOJ1856 [SCOI2010]生成字符串 【组合数】
题目 lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数.现在lxhgww想要知道满足要求 ...
- mysql 查询死锁语句
我们可以用下面三张表来查原因: innodb_trx ## 当前运行的所有事务 innodb_locks ## 当前出现的锁 innodb_lock_wait ...
- js使用笔记
js使用技巧总结 1,onclick有效是结合alter弹出框 <!DOCTYPE html> <html> <head lang="en"> ...
- FZOJ Problem 2148 Moon Game
Proble ...
- 【BZOJ4555】【TJOI2016】【HEOI2016】求和 (第二类斯特林数+NTT卷积)
Description 在2016年,佳媛姐姐刚刚学习了第二类斯特林数,非常开心. 现在他想计算这样一个函数的值: $$f(n)=\sum_{i=0}^n\sum_{j=0}^i S(i,j)\tim ...
- 部署 DevStack
本节按照以下步骤部署 DevStack 实验环境,包括控制节点和计算节点 创建虚拟机 按照物理资源需求创建 devstack-controller 和 devstak-compute 虚拟机 安装操作 ...
- 【CF733F】Drivers Dissatisfaction(最小瓶颈生成树,倍增)
题意:给出一个图,每条边有权值和花费c,每次花费c能使的权值-1.给出一个预算,求减完权值后的一个最小生成树. 思路:感谢CC大神 有这样一个结论:最佳方案里必定存在一种,预算全部花费全部分配在一条边 ...