简体   繁体   English

C#对象引用未设置为对象的实例(在堆栈跟踪中未提及空引用)

[英]c# object reference not set to an instance of an object (no mention of null reference in stack trace)

I am getting a "Object reference not set to an instance of an object" error when running my windows service in Release mode (please note, as you can see from my stack trace, it doesn't mention anything to do with a NullReference which is confusing me more). 在发布模式下运行Windows服务时,出现“对象引用未设置为对象实例”错误(请注意,正如您从堆栈跟踪中看到的那样,它没有提及与NullReference有关的任何内容让我更加困惑)。 Each time i run this in debug mode, the code works beautifully, but as soon as i build it to release and start it on the server, it fails with the Object reference error. 每次我在调试模式下运行此代码时,代码都能正常工作,但是一旦我构建它以在服务器上发布并启动它,它就会因对象引用错误而失败。 See below for my stack trace and then below that for my code; 请参阅下面的堆栈跟踪,然后在下面的代码跟踪。

=================================================================================

Error Message: [EventQueueBulkProcessingHandler] Failed to process events
Stack Trace: 

Error Message (INNER EXCEPTION LEVEL 1): Object reference not set to an instance of an object.
Stack Trace (INNER EXCEPTION LEVEL 1):
   at Voicebox.EventTriggers.Processing.Preparation.EventContactsFilter.Filter(ContactsModel contacts, ContactsFilterModel contactsFilterModel, Int32 clientId) in D:\Websites\VoiceboxTest\Voicebox\VoiceBox.EventTriggers\Processing\Preparation\EventContactsFilter.cs:line 24
   at Voicebox.EventTriggers.Processing.Preparation.TriggerActionDetailsBuilder.CreateTriggerActionDetails(Trigger trigger, ITriggerEvent triggerEvent) in D:\Websites\VoiceboxTest\Voicebox\VoiceBox.EventTriggers\Processing\Preparation\TriggerActionDetailsBuilder.cs:line 48
   at Voicebox.EventTriggers.Processing.Handlers.UserEventsHandler.<>c__DisplayClass6_0.<MapEventsToTriggers>b__0(Trigger t, ITriggerEvent e) in D:\Websites\VoiceboxTest\Voicebox\VoiceBox.EventTriggers\Processing\Handlers\UserEventsHandler.cs:line 62
   at Voicebox.EventTriggers.Helpers.PermutationsHelper.<>c__DisplayClass0_1`3.<Permutations>b__1(TB b) in D:\Websites\VoiceboxTest\Voicebox\VoiceBox.EventTriggers\Helpers\PermutationsHelper.cs:line 11
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Voicebox.EventTriggers.Processing.Handlers.UserEventsHandler.<HandleAsync>d__5.MoveNext() in D:\Websites\VoiceboxTest\Voicebox\VoiceBox.EventTriggers\Processing\Handlers\UserEventsHandler.cs:line 37
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Voicebox.EventTriggers.Processing.EventQueueBulkProcessingHandler.<ProcessEventsGrouppedByClient>d__8.MoveNext() in D:\Websites\VoiceboxTest\Voicebox\VoiceBox.EventTriggers\Processing\EventQueueBulkProcessingHandler.cs:line 107
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Voicebox.EventTriggers.Processing.EventQueueBulkProcessingHandler.<ProcessInternal>d__6.MoveNext() in D:\Websites\VoiceboxTest\Voicebox\VoiceBox.EventTriggers\Processing\EventQueueBulkProcessingHandler.cs:line 52

=================================================================================

So going off of the above stack trace, it says the issue is in the file EventContactsFilter at line 24. This is where its making no sense to me as this is the initialisation of a List. 因此,从上面的堆栈跟踪中可以看出,问题出在第24行的EventContactsFilter文件中。这对我来说毫无意义,因为这是List的初始化。 See below code; 见下面的代码;

            // this is the line 24 which the stack trace points too
            List<string> filterExpressions = new List<string>();

            foreach (var model in contactsFilterModel.Criteria)
            {
                string fieldName = GetFieldName(contacts.ListId, model.FieldID, clientId);

                FieldType fieldType = GetFieldType(model);
                FilterExpression FilterExpression = ExpressionBuilder.GetFilterExpression(fieldName, model, fieldType);
                var expression = FilterExpression.sqlExpression;
                filterExpressions.Add(expression);
            }

So as you can see, the error is being thrown on the creation of a new list, and after many many hours or searching the web, ive not been able to find out what may be causing this. 因此,正如您所看到的,创建新列表时会抛出该错误,并且经过许多小时或在网上搜索后,我仍无法找出可能导致此问题的原因。 If anyone is able to help, i would be forever in your debt!! 如果有人能够提供帮助,我将永远在您的债务中!!

I'm not really convinced that the problem is the List<string> declaration. 我不是很确定问题是List<string>声明。 Please use a try-catch around that declaration, and see what the actual error message is. 请在该声明周围使用try-catch ,并查看实际的错误消息是什么。

My intuition says the problem it's not there. 我的直觉说问题不存在。 Maybe something above,or under that line. 也许在那条线的上方或下方。 My guess that foreach . 我的猜测是foreach Either way, try-catch that code :) 无论哪种方式,请try-catch该代码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM