NHibernate - 缺少 dll
// this._cfg
是一个 NHibernate 配置实例
this._sessionFactory = this._cfg.BuildSessionFactory();
在运行时(而不是在编译时)给我这个异常。
无法加载文件或程序集“NHibernate.ByteCode.Castle”或其依赖项之一。系统找不到指定的文件。":"NHibernate.ByteCode.Castle
到目前为止正常。但问题是,这段代码正在一个类库项目中运行,并且我在该项目中引用了 NHibernate.ByteCode.Castle(以及所有其他 NHibernate dll)。
Wierder:我可以通过另外引用调用我的类库的 Windows WPF 可执行项目中的 NHibernate dll 来修复该异常。但是 Windows WPF 可执行文件不包含直接使用 NHibernate 的代码(证据如下:它可以在没有任何 NHibernate 引用的情况下编译良好)。那么到底是怎么回事呢?显然,在实际使用 NHibernate 东西的项目中引用 NHibernate.ByteCode.Castle 是不够的。有人知道为什么吗?
This call
// this._cfg is an NHibernate Configuration instance
this._sessionFactory = this._cfg.BuildSessionFactory();
Gives me this exception at runtime (NOT at compile time).
Could not load file or assembly 'NHibernate.ByteCode.Castle' or one of its dependencies. The system cannot find the file specified.":"NHibernate.ByteCode.Castle
OK so far. But the thing is, this code is running in a class library project, and I have referenced NHibernate.ByteCode.Castle (along with all the other NHibernate dll's) in that project.
Wierder: I can fix the exception by additionally referencing the NHibernate dll's in the Windows WPF executable project that calls my class library. But the Windows WPF executable contains no code that directly uses NHibernate (as evidenced by: It compiles fine without any NHibernate references). So what's going on? Apparently it's insufficient to reference NHibernate.ByteCode.Castle in the project that actually uses the NHibernate stuff. Anyone know why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这已经很旧了,但是我为解决依赖性问题所做的事情很简单:
在我的 UnitOfWork 中,我添加了一个静态方法:
然后,只有到那时,MSBuild 才会发现需要它并将其复制到我的输出目录中我的(asp.net 和控制台)应用程序引用了我的数据项目。
I know this is old, but what I've done to fix the dependency problem is simple:
In my UnitOfWork I added one static method:
Then, and only then, would MSBuild see that it was needed and copy it to my output directory for my (asp.net and console) apps that references my Data project.
我根本不会引用城堡字节码工厂;只需确保使用构建后步骤将其(以及所有其他所需的依赖项)复制到输出目录即可。
I wouldn't reference the castle byte code factory at all; just ensure it (and all other needed dependancies) are copied to the output directory using a post-build step.