Select Page

When doing a Single lookup from database getting error.

XeroBankAccount bankAccount = xeroBankAccountService.Table.Single(p => p.Guid == guid);

Gets below exception line:

System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at lambda_method(Closure )
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ResultEnumerable`1.GetEnumerator()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities[TOut,TIn](IEnumerable`1 results, QueryContext queryContext, IList`1 entityTrackingInfos, IList`1 entityAccessors)+MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass15_1`1.<CompileQueryCore>b__0(QueryContext qc)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Single[TSource](IQueryable`1 source, Expression`1 predicate)
   at Bot.Crawler.Tests.IngCrawlerTests.Ing_DownloadStatement_and_UploadToXero(AccountHolderType accountHolderType, String 

Solution:

It appears the GUID was stored in the database with small case but to ensure this does not run into exception you can use FirstOrDefault()

XeroBankAccount bankAccount = xeroBankAccountService.Table.FirstOrDefault(p => p.Guid == guid);
OpenQA.Selenium.InvalidSelectorException: 'invalid selector: Unable to locate an element with the xpath expression //*[contains(text()='Open de Mobiel Bankieren App')] because of the following error:
NotSupportedError: Failed to execute 'evaluate' on 'Document': The node provided is '#document-fragment', which is not a valid context node type.

OpenQA.Selenium.InvalidSelectorException: ‘invalid selector: Unable to locate an element with the xpath expression //*[contains(text()=’Open de Mobiel Bankieren App’)] because of the following error:
NotSupportedError: Failed to execute ‘evaluate’ on ‘Document’: The node provided is ‘#document-fragment’, which is not a valid context node type.