An exception is thrown when the type Initial Value of nhib.pdf. Cfg. Configuration is set.

Source: Internet
Author: User
Tags log4net

An exception is thrown when the type Initial Value of nhib.pdf. Cfg. Configuration is set.

During the design of castle activerecord, exceptions are often caused by the type of "nhib.pdf. Cfg. Configuration. At that time, I didn't know what was going on. It was all done. Who knows that after I modified some things for the second time, I got this error prompt again, but I didn't know why at the time, after half a day of exploration, we used to embed xml into resources.

If your project contains configuration files such as App. config, set them to "embedded resources" so that no errors will occur when you run the program again.

View detailed tutorial

Using nhib.pdf;
Using nhib.pdf. Cfg;

Configuration cfg = new Configuration ();
An exception occurs when you set the type of "NHibernate. Cfg. Configuration.
Why? I introduced dll and namespace.
[Analysis 1]
Further Look at the error message, such as InnerException:
{"Failed to Load file or assembly" log4net, Version = 1.2.9.0, Culture = neutral, PublicKeyToken = b32731d11ce58905 "or one of its dependencies. The system cannot find the specified file. ":" Log4net, Version = 1.2.9.0, Culture = neutral, PublicKeyToken = b32731d11ce58905 "} the problem may be caused by log4net.
[Solution]
Sure enough, add the following section to the app. config file:

<Log4net>
<Appender name = "NHibernateFileLog" type = "log4net. Appender. RollingFileAppender">
<File value = "Logs/nhibernate.txt"/>
<AppendToFile value = "true"/>
<RollingStyle value = "Size"/>
<MaxSizeRollBackups tutorial value = "10"/>
<MaximumFileSize value = "100KB"/>
<StaticLogFileName value = "true"/>
<Layout type = "log4net. Layout. PatternLayout">
<ConversionPattern value = "% d {HH: mm: ss. fff} [% t] %-5 p % c-% m % n"/>
</Layout>
</Appender>

<Appender name = "GeneralLog" type = "log4net. Appender. RollingFileAppender">
<File value = "Logs/general.txt"/>
<AppendToFile value = "true"/>
<MaximumFileSize value = "100KB"/>
<RollingStyle value = "Size"/>
<MaxSizeRollBackups value = "5"/>
<Layout type = "log4net. Layout. PatternLayout">
<ConversionPattern value = "% d {HH: mm: ss. fff} [% t] %-5 p % c-% m % n"/>
</Layout>
</Appender>
<Appender name = "DataLog" type = "log4net. Appender. RollingFileAppender">
<File value = "Logs/data.txt"/>
<AppendToFile value = "true"/>
<MaximumFileSize value = "100KB"/>
<RollingStyle value = "Size"/>
<MaxSizeRollBackups value = "5"/>
<Layout type = "log4net. Layout. PatternLayout">
<ConversionPattern value = "% d {HH: mm: ss. fff} [% t] %-5 p % c-% m % n"/>
</Layout>
</Appender>

<! -- Levels: DEBUG, INFO, WARN, ERROR, FATAL -->

<Root>
<Level value = "DEBUG"/>
<Appender-ref = "GeneralLog"/>
</Root>

<Logger name = "nhib.pdf" additi.pdf = "false">
<Level value = "DEBUG"/>
<Appender-ref = "NHibernateFileLog"/>
</Logger>
<Logger name = "Pushable. Data" additivity = "false">
<Level value = "DEBUG"/>
<Appender-ref = "DataLog"/>
</Logger>
</Log4net>

Modify the configSections section as follows:

<ConfigSections>
<Section name = "nhibernate" type = "System. Configuration. NameValueSectionHandler, System,
Version = 1.0.5000.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 "/>
<Section name = "log4net" type = "log4net. Config. Log4NetConfigurationSectionHandler, log4net"/>
</ConfigSections>

That is, add log4net, or an error will be reported. New configuration () passed

[New question]
When executed:

ISessionFactory factory = config. BuildSessionFactory (); error:
{"Failed to Load file or assembly" Iesi. Collections, Version = 1.0.0.1, Culture = neutral, PublicKeyToken = 154fdcb44c4484fc "or one of its dependencies. The system cannot find the specified file. ":" Iesi. Collections, Version = 1.0.0.1, Culture = neutral, PublicKeyToken = 154fdcb44c4484fc "}
[Solution]

Copy Iesi. Collections. dll from the nhibernate-1.0.4.0bin directory to another directory (or do not copy) and then reference it to the Project

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.