Есть служба Windows, которая слушает MSMQ. В методе OnStart есть это
protected override void OnStart(string[] args)
{
try
{
_queue = new MessageQueue(_qPath);//this part works as i had logging before and afer this call
//Add MSMQ Event
_queue.ReceiveCompleted += new ReceiveCompletedEventHandler(queue_ReceiveCompleted);//this part works as i had logging before and afer this call
_queue.BeginReceive();//This is where it is failing - get a null reference exception
}
catch(Exception ex)
{
EventLogger.LogEvent(EventSource, EventLogType, "OnStart" + _lineFeed +
ex.InnerException.ToString() + _lineFeed + ex.Message.ToString());
}
}
где
private MessageQueue _queue = null;
Это работает на моем компьютере, но при развертывании на сервере Windows 2003 и запуске в качестве учетной записи сетевой службы происходит сбой
Исключение recvd:
Service cannot be started. System.NullReferenceException: Object reference not set to an instance of an object.
at MYService.Service.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
Решено:
Оказалось, что Q, который я настроил, мне пришлось явно добавить к нему учетную запись сетевой службы на вкладке безопасности