FluentNHibernate 在 Windows 服务中崩溃,但在网站中没有崩溃
我有一个类库来完成我所有的 NHibernate 工作。它还使用 Fluent NHibernate 处理所有映射 - 无需部署映射文件。
该类库由许多应用程序使用,包括在我的计算机上运行的 Windows 服务。虽然它在我的所有 Web 应用程序中工作正常,但 Windows 服务在尝试使用 NHibernate 时会收到此消息:
创建 SessionFactory 时使用了无效或不完整的配置。检查 PotentialReasons 集合和 InnerException 了解更多详细信息。 在 FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() 在 C:\Kctc\Trunk\Kctc.NHibernate\KctcSessionFactory.cs 中的 Kctc.NHibernate.KctcSessionFactory.get_SessionFactory() 处:第 28 行 ...更多堆栈跟踪...
我已经检查了 InnerException,但似乎没有。我不知道 PotentialReasons 集合是什么,Google 似乎也没有提供。
这是我的开发计算机,因此当我处理 Web 应用程序时,它们在本地运行(即使用 Visual Studio 中的 Web 服务器)。 Windows 服务和我的开发 Web 应用程序在同一台计算机上运行这一事实表明,这与信任设置或您拥有的其他内容无关。
谁能建议我应该尝试什么?这是我感到非常困惑的问题之一,我什至不知道如何获得有关该问题的更多信息。
I've got a class library doing all my NHibernate stuff. It also handles all the mapping using Fluent NHibernate - no mapping files to deploy.
This class library is consumed by a number of apps, including a Windows Service running on my computer. Although it works fine in all my web apps, the Windows Service gets this when it tries to use NHibernate:
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at Kctc.NHibernate.KctcSessionFactory.get_SessionFactory() in C:\Kctc\Trunk\Kctc.NHibernate\KctcSessionFactory.cs:line 28
...more stack trace...
I have checked for an InnerException and there doesn't appear to be one. I have no idea what the PotentialReasons collection is, and Google doesn't seem to be forthcoming either.
This is my dev machine, so when I'm working on my web apps they run locally (i.e. using the web server in Visual Studio). The fact that the Windows Service and my dev web apps are running on this same machine suggest it's not to do with trust settings or what have you.
Can anyone suggest what I should try? This is one of those ones where I'm so stumped I can't even think of how to get more information about the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只是一个疯狂的猜测。 NHibernate 从执行目录中获取 hibernate.cfg.xml 文件。您是否配置了服务的执行目录以使其可以找到该文件?
Just a wild guess. NHibernate picks up the
hibernate.cfg.xml
file from the execution directory. Did you configure the execution directory of the service that it can find this file?我已经知道问题出在哪里了。该服务未使用所需的 NHibernate.ByteCode.LinFu.dll 进行部署。
我似乎一直存在 Visual Studio 编译器在构建过程中不总是将间接依赖项(即应用程序所需的类库所需的 dll)复制到输出文件夹中的问题。我真的应该早点想到这一点。
谢谢你们为我绞尽脑汁。
I've found out what the problem is. The Service did not deploy with the required NHibernate.ByteCode.LinFu.dll.
I appear to have an ongoing problem with the Visual Studio compiler not always copying indirect dependencies (i.e. dlls required by class libraries required by the app) into the output folder during the build. I should have thought of this sooner really.
Thanks for racking your brains on my behalf guys.
我敢打赌 app.config 中缺少连接字符串的名称。对我来说,该消息几乎完全是缺少连接字符串。
您的目标是同一个数据库还是数据库之间存在某种架构不匹配?
是否是服务上的身份验证问题,例如您使用无法使用的 Windows 身份验证(或不起作用的 sql 身份验证)?
没有代码的时候很难说,只有例外!
编辑您是否曾经使用过 HttpContext、HostingEnvironment 或其他特定于“网络”的内容?
I bet the name of the connection string is missing from the app.config. For me that message is almost exclusively a missing connection string.
Are you targeting the same database or could it be some sort of schema mismatch between databases?
Could it be authentication issues on the service like you use windows authentication where it can't be used (or the sql authentication that doesn't work)?
It's hard to tell when there is no code, just an exception!
EDIT Are you ever using HttpContext, HostingEnvironment or anything else specific to "web"?