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