question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Index was out of range

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:36 (21 by maintainers)

github_iconTop GitHub Comments

2reactions
MaceWinducommented, Nov 22, 2020

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

1reaction
devhl-labscommented, Nov 16, 2020

That worked though.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found