Index was out of range
See original GitHub issueI am running dbContext.BulkCopyAsync twice. It works the first time. The second time it completes the insert, but then throws an index out of range error. If I continue, then I get a Npgsql.NpgsqlException: 'Exception while reading from stream'
TimeoutException: Timeout during reading attempt
. I am using EF Core 5.0. I have a converter in place to handle my ulongs. There are ulongs in the orgs type, so that doesn’t seem to be it.
Exception message:
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')'
Stack trace:
This exception was originally thrown at this call stack:
System.ThrowHelper.ThrowArgumentOutOfRange_IndexException() in ThrowHelper.cs
Npgsql.NpgsqlDataReader.ProcessMessage(Npgsql.IBackendMessage) in NpgsqlDataReader.cs
Npgsql.NpgsqlDataReader.NextResult(bool, bool, System.Threading.CancellationToken) in NpgsqlDataReader.cs
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in ExceptionDispatchInfo.cs
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) in TaskAwaiter.cs
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) in TaskAwaiter.cs
Npgsql.NpgsqlCommand.ExecuteReader(System.Data.CommandBehavior, bool, System.Threading.CancellationToken) in NpgsqlCommand.cs
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in ExceptionDispatchInfo.cs
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) in TaskAwaiter.cs
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) in TaskAwaiter.cs
...
[Call Stack Truncated]
Steps to reproduce
var options = new LinqToDB.Data.BulkCopyOptions
{
KeepIdentity = true
};
await dbContext.BulkCopyAsync(options, orgs);
await dbContext.BulkCopyAsync(options, leagues); // index out of range
public class League
{
public int Id { get; set; }
public LeagueState State { get; set; }
public ulong ChannelId { get; set; }
public string Initials { get; set; } = string.Empty;
public string? Image { get; set; }
public int OrgId { get; set; }
public Org Org { get; set; }
public int Season { get; set; }
public int? WarMatchId { get; set; }
public List<Participant> Participants { get; set; }
}
Environment details
linq2db version: 3.1.6 Database Server: Postgres Database Provider: Npgsql Operating system: Windows 10 .NET Framework: .net 5.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:36 (21 by maintainers)
Top Results From Across the Web
Index was out of range. Must be non-negative and less ...
The error says "The index is out of range". That means you were trying to index an object with a value that was...
Read more >how to solve index was out of range. must be non-negative ...
Solution 1 Without the actual code to work from, we can't be that precise. But the error is pretty clear: You are accessing...
Read more >[Solved] Index was out of range. Must be non-negative and ...
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index.
Read more >Index was out of range. Must be non-negative and less ...
In the 1st video tutorial I encounter the "Index was out of range. Must be non-negative and less than the size of the...
Read more >Error 'Index was out of range. Must be non-negative and ...
I have version 2.0.6 of module ExchangeOnlineManagement installed and I am using WindowsPowerShell 5.1. I issue the following connect ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like something wrong with async in npgsql 5, as we are getting errors from async code even from other providers when run tests alongside with npgsql. I will investigate and report it to npgsql repo
That worked though.