Thursday, 25 October 2007

Configuration exception for log4Net

I have been battling with the following error, for almost three days now:

System.Configuration.ConfigurationException: Error loading XML file c:\windows\microsoft.net\framework\v1.0.3705\Config\machine.config Request for the permission of type System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed. (c:\windows\microsoft.net\framework\v1.0.3705\Config\machine.config)


I have developed a proxy client which worked perfect when I ran my NUnit tests, but when I tried to make an external application which should use it, there was this error. I finally found the it was a version mismatch between two version of log4net, where I had used 1.0 net version for developing my proxy, I had by mistake added the 1.1 net version of log4net to the application.

Same problem also gave me the following error:


System.TypeInitializationException: The type initializer for "log4net.GlobalContext" threw an exception. ---> System.TypeLoadException: Invalid PInvoke metadata format.
at System.Net.OSSOCK.gethostname(StringBuilder hostName, Int32 bufferLength)
at System.Net.Dns.GetHostName()
at log4net.Util.SystemInfo.get_HostName()
at log4net.GlobalContext..cctor()
--- End of inner exception stack trace ---
at log4net.GlobalContext.get_Properties()
at log4net.Core.LoggingEvent.CreateCompositeProperties()
at log4net.Core.LoggingEvent.LookupProperty(String key)
at log4net.Layout.Pattern.NdcPatternConverter.Convert(TextWriter writer, LoggingEvent loggingEvent)
at log4net.Layout.Pattern.PatternLayoutConverter.Convert(TextWriter writer, Object state)
at log4net.Util.PatternConverter.Format(TextWriter writer, Object state)
at log4net.Layout.PatternLayout.Format(TextWriter writer, LoggingEvent loggingEvent)
at log4net.Appender.AppenderSkeleton.RenderLoggingEvent(TextWriter wriSystem.TypeInitializationException: The type initializer for "log4net.GlobalContext" threw an exception. ---> System.TypeLoadException: Invalid PInvoke metadata format.
at System.Net.OSSOCK.gethostname(StringBuilder hostName, Int32 bufferLength)
at System.Net.Dns.GetHostName()


So if you are fighting with a similar problem, check the versions of you .NET framework and the version of the log4net.

The hint was to read this (link)

2 comments:

Anonymous said...

Generally I do not post on blogs, but I would love to mention that this post extremely forced me to try and do therefore! really nice post. thanks, here's a similar subject you'll like [url=http://sandbox.wikidot.com/the-advantages-of-owning-a-natural-light-alarm-clock]Old Clocks[/url]

Anonymous said...

Wow that was unusual. I just wrote an really long comment but after I clicked submit
my comment didn't appear. Grrrr... well I'm not writing all that over again.
Regardless, just wanted to say superb blog!


Take a look at my site bmi chart women