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.

Exception message thrown by SingleAsync, when sequence contains no element, is vague

See original GitHub issue

Entity Framework Core’s extension method SingleAsync throws an exception, if more than one element exists. The message of this exception is vague and does not match with it’s synchronous LINQ counterpart Single.

For comparison this is the message for the exception that is thrown by the Single method.

System.InvalidOperationException: Sequence contains more than one matching element.

And here the exception message thrown by SingleAsync, which doesn’t really tell us what the actual problem is:

System.InvalidOperationException: ‘Enumerator failed to MoveNextAsync.’

Expectation: The exception messages should be equal for both the synchronous and the asynchronous version.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:32
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

8reactions
pavinancommented, Nov 6, 2019

@ajcvickers The message returned is correct in ef core 2.2. This is only happening in ef core 3.0. The entire stack strace is changed. May be this should be considered a bug rather than enhancement.

7reactions
guiportooocommented, Jan 30, 2020

The same happens with FirstAsync, when no element is returned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Sequence contains no elements?
When you get the LINQ error "Sequence contains no elements", this is usually because you are using the First() or Single() command rather...
Read more >
Sequence contains no elements, ERROR - Microsoft Q&A
it is an old Entity Framework application that I am trying to reconstruct and get running. Server Error in '/' Application. ... Description:...
Read more >
[Solved] Sequence contains no elements(system. ...
Sequence contains no elements (system.invalidoperationexception: sequence contains no elements).
Read more >
sequence contains no elements in c# sql - YouTube
How to solve sequence contains no elements in asp.net c# with sql. why show this error sequence contains no elements ...
Read more >
Reliably testing code that adopts Swift Concurrency? - ...
I'm having a hard time figuring out how to test application code as it adopts async-await and begins to be scheduled concurrently.
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