简体   繁体   中英

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). 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. 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. Please use a try-catch around that declaration, and see what the actual error message is.

My intuition says the problem it's not there. Maybe something above,or under that line. My guess that foreach . Either way, try-catch that code :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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