小弟刚学Nhibernate 软件vs2008
TestProject2.UnitTest1.TestMethod1 引发异常: NHibernate.Cfg.HibernateConfigException: An exception occurred during configuration of persistence layer. ---> System.IO.DirectoryNotFoundException: 未能找到路径“c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies;PrivateAssemblies\hibernate.cfg.xml”的一部分。 而且在编辑测试运行配置中,已经进行了部署,使了把hibernate.cfg.xml复制到TestResults还是不好用,如果新建个控制台可以运行程序,hibernate.cfg.xml设置了总是复制
小弟运行建NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration().Configure();
SchemaExport schemaExport = new SchemaExport(cfg);
schemaExport.Create(true, true); 就报错了 还没到调用SessionFactory
@喧闹幽静: XML文件的默认“复制到输出目录”为“不复制”,这里需要修改为“始终复制”。否则出现“failed: NHibernate.Cfg.HibernateConfigException : An exception occurred during configuration of persistence layer. ----> System.IO.FileNotFoundException : 未能找到文件“NHibernateSample\NHibernateSample.Data.Test\bin\Debug\hibernate.cfg.xml””异常。
@小小刀: 这个已经修改过了
@喧闹幽静: 你是在哪里写的hibernate.cfg.xml的地址?
@小小刀: 那篇文章以前看过了还是没发现 谢谢哥
@小小刀: 实体类和 映射文件的那个类库
@喧闹幽静: 你应该是没有设置的hibernate.cfg.xml 的路径
XmlDocument cfgXml = new XmlDocument(); cfgXml.Load("TestEnbeddedConfig.cfg.xml");
// this should put us at the first <property> element XmlElement propElement = cfgXml.DocumentElement.GetElementsByTagName("property")[0] as XmlElement;
// removing this will cause it not to validate propElement.RemoveAttribute("name");
const string FileNameForInvalidCfg = "hibernate.invalid.cfg.xml"; cfgXml.Save(FileNameForInvalidCfg);
Configuration cfg = new Configuration(); try { cfg.Configure(FileNameForInvalidCfg); } catch (HibernateException) { // just absorb it - not what we are testing } finally { // clean up the bad file - if the Configure method cleans up after // itself we should be able to do this without problem. If it does // property release the resource then this won't be able to access // the file to delete. File.Delete(FileNameForInvalidCfg); }
@小小刀:
Configuration cfg = new Configuration();
cfg.Configure(this.GetType().Assembly, "NHibernate.Test.TestEnbeddedConfig.cfg.xml");
@小小刀: 请问下这个是在哪设置的