开发者

NHibernate throwing log4net exception, telling me well formed XML may be invalid?

I've got a crappy console application I've been playing with to try to get NHibernate going. I'm struggling with how fickle it is and it has a nasty habit of throwing exceptions that are difficult to find solutions for.

Today, I've started my project up and tried to run it and I'm getting errors in log4net, which I haven't even directly referenced in any way. I've reduced my app to the following code and it still happens:

class Program {
    public static void Main(string[] args) {
        Configuration conf = new Configuration();
        Console.Write("Press any key to continue . . . ");
        Console.ReadKey(true);
    }
}

The truncated error output I get is:

log4net:ERROR DefaultRepositorySelector: Exception while reading ConfigurationSettings. Check your .config file is well formed XML.
System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for appSettings: External component has thrown a

The error appears to nest about 10 times before SharpDevelop takes over and gives me an exception dialog.

I have a separate hibernate configuration file and a mapping file but neither is included as either an embedded resource or copied to the output directory. The app.config is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime ver开发者_StackOverflowsion="v4.0" sku=".NETFramework,Version=v4.0" />
    </startup>

    <appSettings>
    </appSettings>
</configuration>

The error still happens without the @startup@ section. There is no reference to nhibernate-configuration in this file - I'm loading it after instantiating the Configuration class.

This wouldn't be so frustrating if it wasn't working just fine yesterday, and I've changed nothing but adding two fields to the mapping (which I removed again when it didn't work, which didn't help).

I'm really at a loss as to how to stop this error from happening. Any help would be greatly appreciated.


After I think there is usually a element. Seems like it may be looking for one of those. Here is a link to an nHibernate configuration that shows a sample:

http://www.beansoftware.com/ASP.NET-Tutorials/NHibernate-Log4Net.aspx

Hope this points you in the right direction.

Bob


Here is what I would recommend

  1. Turn on internal debugging so you can see why Log4Net is throwing an exception
  2. Perhaps configure a Console Appender to see the log entries in your console

Hopefully this will assist you in discovering the issues.


I vaguely recall running into an error like this while using log4net. I don't remember what exactly fixed it, but try the following.

  1. Even without a direct reference to log4net, make sure it's configured properly per the Apache page (http://logging.apache.org/log4net/release/manual/configuration.html) and include the configure command in your main for good measure.

    XmlConfigurator.Configure();
    
  2. If the appSettings section is empty, that may throw an exception. Try getting rid of it entirely. Better yet, throw a dummy node in there. (yes, dummy values are better for some reason that I, nor anyone else, can explain, ever)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜