log4net: Assembly System.Xml.XmlElement not referenced error, although not used
I'm getting a weird compiler error when using log4net:
XmlConfigurator.Configure(new FileInfo("LogConfig.log4net")); // produces error
ILog log = LogManager.GetLogger("MyLogger");
log.Info("hello");
reports
Error 1 The type 'System.Xml.XmlElement' is def开发者_运维技巧ined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
This happens on the first line, although I do not really mention any System.Xml things there myself. Also, it is probably noteworthy that I target .net 4.0 and the compiler demands the .net 2.0 assembly. I just recently switched my project to target 4.0.
Any suggestions? Thanks!
I suspect the problem is that you're calling a method with an overload using a parameter of type XmlElement
. While I can see the argument for it not failing, I think it's not entirely unreasonable to require the reference.
The simplest fix is just to add a reference to System.Xml.dll - it doesn't really need the .NET 2.0 version; it's just that that's the one that the log4net assembly references.
精彩评论