【发布时间】:2026-01-14 03:40:03
【问题描述】:
我正在尝试使用 C# 和 .NET 框架编写我的第一个 Windows 服务,但无法在服务内的同一解决方案中引用项目。我在 VS2012 中的 MVC 解决方案结构:
- 1 个 MVC 项目(网络应用项目)
- 1 个附加处理项目(用于控制器内的扩展处理)
- 1个服务项目
- 1安装shield le项目(成功安装服务项目)
在我的服务中(我想每 x 分钟触发一次)我在扩展处理项目中引用方法,当我在服务项目中编写代码时,intellisense 能够检测到这些方法(我有一个 using extendedProcessingProject; using webAppProject;以及对 extendedProcessingProject 和 web 应用程序项目的项目引用)。
该服务安装到我的本地电脑没有错误。当我启动服务时,我记录了一个我似乎无法弄清楚的错误:
Exception body: ReminderEmailService Object reference not set to an instance of an object. System.Collections.ListDictionaryInternal
System.NullReferenceException: Object reference not set to an instance of an object.
at ReminderEmailService.ReminderEmailService.ReminderEmails(Object source, ElapsedEventArgs e)
at ReminderEmailService.ReminderEmailService.SendReminderEmails(Object source, ElapsedEventArgs e)
无效的 SendReminderEmails(System.Object, System.Timers.ElapsedEventArgs)
我知道使用System.Diagnostics.Debugger.Launch(); 可以看到
List<SessionReminder> sessions = Queries.GetSessionsToRemind();
//sessions does not have a value, method returns a list of 1
//I suspect this is a project reference issue
debugString += "sessions: \n" + sessions.ToString();
//exception thrown on this line--I suspect because sessions is null
我在我的解决方案中的所有项目上都使用 .NET4.0(不是客户端配置文件)。任何有关如何使我的 Windows 服务能够正确访问这些程序集(webappproject.dll 和 extendedProcessing.dll)的见解将不胜感激,因为这些 dll 是由 install shield 安装的。
【问题讨论】:
标签: c# .net asp.net-mvc visual-studio-2012 windows-services