Exception ArgumentOutOfRangeException #467

Closed
opened 2025-12-29 08:28:37 +01:00 by adam · 11 comments
Owner

Originally created by @arihantjain0894 on GitHub (Nov 15, 2022).

Originally assigned to: @StefH on GitHub.

Hi, I am getting the following exception:

System.ArgumentOutOfRangeException
Message: Index was out of range. Must be non-negative and less than the size of the collection.
InnerException: null 
StackTraceString: at System.Collections.Generic.List`1.get_Item(Int32 index)
at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index)
at WireMock.Owin.WireMockMiddleware.LogRequest(LogEntry entry, Boolean addRequest)
at WireMock.Owin.WireMockMiddleware.InvokeInternalAsync(HttpContext ctx)
at WireMock.Owin.GlobalExceptionMiddleware.InvokeInternalAsync(HttpContext ctx)

Settings:
"MaxRequestLogCount": 0
"CustomDelay": 5000 ms

Version: 1.5.3

Usage: System stress testing.

When i increase the MaxRequestLogCount to let say 20, this is less frequent.
Also making custom delay to 0 fixes this.

Originally created by @arihantjain0894 on GitHub (Nov 15, 2022). Originally assigned to: @StefH on GitHub. Hi, I am getting the following exception: ``` System.ArgumentOutOfRangeException Message: Index was out of range. Must be non-negative and less than the size of the collection. InnerException: null StackTraceString: at System.Collections.Generic.List`1.get_Item(Int32 index) at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index) at WireMock.Owin.WireMockMiddleware.LogRequest(LogEntry entry, Boolean addRequest) at WireMock.Owin.WireMockMiddleware.InvokeInternalAsync(HttpContext ctx) at WireMock.Owin.GlobalExceptionMiddleware.InvokeInternalAsync(HttpContext ctx) ``` Settings: "MaxRequestLogCount": 0 "CustomDelay": 5000 ms Version: 1.5.3 Usage: System stress testing. When i increase the MaxRequestLogCount to let say 20, this is less frequent. Also making custom delay to 0 fixes this.
adam added the bug label 2025-12-29 08:28:37 +01:00
adam closed this issue 2025-12-29 08:28:37 +01:00
Author
Owner

@StefH commented on GitHub (Nov 17, 2022):

https://github.com/WireMock-Net/WireMock.Net/pull/848

@StefH commented on GitHub (Nov 17, 2022): https://github.com/WireMock-Net/WireMock.Net/pull/848
Author
Owner

@StefH commented on GitHub (Nov 17, 2022):

can you try preview version "1.5.10-ci-16658" ?

(https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)

@StefH commented on GitHub (Nov 17, 2022): can you try preview version "1.5.10-ci-16658" ? (https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)
Author
Owner

@arihantjain0894 commented on GitHub (Nov 18, 2022):

{
	"Status": "{\"ClassName\":\"System.ArgumentOutOfRangeException\",\"Message\":\"Index must be within the bounds of the List.\",\"Data\":null,\"InnerException\":null,\"HelpURL\":null,\"StackTraceString\":\"   at System.Collections.Generic.List`1.Insert(Int32 index, T item)\\r\\n   at System.Collections.ObjectModel.Collection`1.InsertItem(Int32 index, T item)\\r\\n   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)\\r\\n   at WireMock.Util.ConcurrentObservableCollection`1.InsertItem(Int32 index, T item)\\r\\n   at WireMock.Owin.WireMockMiddleware.LogRequest(LogEntry entry, Boolean addRequest)\\r\\n   at WireMock.Owin.WireMockMiddleware.InvokeInternalAsync(HttpContext ctx)\\r\\n   at WireMock.Owin.GlobalExceptionMiddleware.InvokeInternalAsync(HttpContext ctx)\",\"RemoteStackTraceString\":null,\"RemoteStackIndex\":0,\"ExceptionMethod\":null,\"HResult\":-2146233086,\"Source\":\"System.Private.CoreLib\",\"WatsonBuckets\":null,\"ParamName\":\"index\",\"ActualValue\":null}"
}

Maybe we need to add try-catch when adding log also.

@arihantjain0894 commented on GitHub (Nov 18, 2022): ``` json { "Status": "{\"ClassName\":\"System.ArgumentOutOfRangeException\",\"Message\":\"Index must be within the bounds of the List.\",\"Data\":null,\"InnerException\":null,\"HelpURL\":null,\"StackTraceString\":\" at System.Collections.Generic.List`1.Insert(Int32 index, T item)\\r\\n at System.Collections.ObjectModel.Collection`1.InsertItem(Int32 index, T item)\\r\\n at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)\\r\\n at WireMock.Util.ConcurrentObservableCollection`1.InsertItem(Int32 index, T item)\\r\\n at WireMock.Owin.WireMockMiddleware.LogRequest(LogEntry entry, Boolean addRequest)\\r\\n at WireMock.Owin.WireMockMiddleware.InvokeInternalAsync(HttpContext ctx)\\r\\n at WireMock.Owin.GlobalExceptionMiddleware.InvokeInternalAsync(HttpContext ctx)\",\"RemoteStackTraceString\":null,\"RemoteStackIndex\":0,\"ExceptionMethod\":null,\"HResult\":-2146233086,\"Source\":\"System.Private.CoreLib\",\"WatsonBuckets\":null,\"ParamName\":\"index\",\"ActualValue\":null}" } ``` Maybe we need to add try-catch when adding log also.
Author
Owner

@StefH commented on GitHub (Nov 18, 2022):

New preview version:

16663

Can you try this?

@StefH commented on GitHub (Nov 18, 2022): New preview version: `16663` Can you try this?
Author
Owner

@StefH commented on GitHub (Nov 19, 2022):

Preview version 16667 does also have extra logic --> do not add an entry at all if the MaxRequestLogCount is set to 0.

@arihantjain0894 can you test this version?

@StefH commented on GitHub (Nov 19, 2022): Preview version `16667` does also have extra logic --> do not add an entry at all if the MaxRequestLogCount is set to 0. @arihantjain0894 can you test this version?
Author
Owner

@arihantjain0894 commented on GitHub (Nov 19, 2022):

Shouldn't we do the same(condition) when removing from the log also?

@arihantjain0894 commented on GitHub (Nov 19, 2022): Shouldn't we do the same(condition) when removing from the log also?
Author
Owner

@StefH commented on GitHub (Nov 19, 2022):

Ok.
I did add some extra checks

@StefH commented on GitHub (Nov 19, 2022): Ok. I did add some extra checks
Author
Owner

@StefH commented on GitHub (Nov 19, 2022):

latest version is 16669

@StefH commented on GitHub (Nov 19, 2022): latest version is 16669
Author
Owner

@arihantjain0894 commented on GitHub (Nov 21, 2022):

Worked fine. Thanks for the fix.

@arihantjain0894 commented on GitHub (Nov 21, 2022): Worked fine. Thanks for the fix.
Author
Owner

@StefH commented on GitHub (Nov 21, 2022):

https://github.com/WireMock-Net/WireMock.Net/pull/848

@StefH commented on GitHub (Nov 21, 2022): https://github.com/WireMock-Net/WireMock.Net/pull/848
Author
Owner

@StefH commented on GitHub (Nov 21, 2022):

New official version will be released shortly.

@StefH commented on GitHub (Nov 21, 2022): New official version will be released shortly.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#467