Source sequence doesn't contain any elements.
See original GitHub issueDescribe the bug When I try to add vertices to Cosmos DB, I get the following message & stack trace.
Error Message: Source sequence doesn’t contain any elements. Stack Trace:
at System.Linq.AsyncEnumerable.<<FirstAsync>g__Core|283_0>d`1.MoveNext() in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/First.cs:line 33
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at RoadHuntin.Library.Core.Create.Handler`2.<Handle>d__3.MoveNext() in E:\Code\RoadHuntinClient\backend\src\RoadHuntin.Library\Core\Create.cs:line 37
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.<Handle>d__2.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.<Handle>d__2.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.<Handle>d__2.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.<Handle>d__2.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MediatR.Pipeline.RequestPostProcessorBehavior`2.<Handle>d__2.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MediatR.Pipeline.RequestPreProcessorBehavior`2.<Handle>d__2.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at RoadHuntin.WebAPI.Controllers.RoutesController.<Post>d__4.MoveNext() in E:\Code\RoadHuntinClient\backend\src\RoadHuntin.WebAPI\Controllers\RoutesController.cs:line 46
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.<Execute>d__0.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<<InvokeActionMethodAsync>g__Logged|12_1>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<<InvokeNextActionFilterAsync>g__Awaited|10_0>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<<InvokeInnerFilterAsync>g__Awaited|13_0>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<<InvokeNextExceptionFilterAsync>g__Awaited|25_0>d.MoveNext()
Expected behavior Vertex should be created and returned.
Version information
- ExRam.Gremlinq.Providers.CosmosDb 8.0.0-preview-0707
- ExRam.Gremlinq.Core 8.0.0-preview-0707
Minimal working example This is the code from where the error is being generated:
DI registration::
services.AddScoped<IGremlinQuerySource>(provider => {
var logger = provider.GetService<ILogger<IGremlinQuerySource>>();
var options = (provider.GetService<IOptions<GremlinOptions>>()).Value;
return g
.ConfigureEnvironment(env => env
.UseLogger(logger)
.UseModel(GraphModel
.FromBaseTypes<Vertex, Edge>(lookup => lookup.IncludeAssembliesOfBaseTypes())
.ConfigureProperties(model => model
.ConfigureElement<Vertex>(conf => conf.IgnoreOnUpdate(x => x.PartitionKey))
)
)
.UseCosmosDb(builder => builder
.At(new Uri(options.EndpointUri), options.Database, options.Container)
.AuthenticateBy(options.PrimaryKey)
.ConfigureWebSocket(builder => builder
.ConfigureQueryLoggingOptions(o => o
.SetQueryLoggingVerbosity(QueryLoggingVerbosity.QueryAndParameters))
)
)
);
});
Code Usage:
var model = _mapper.Map<TEntity>(request);
model = await _g.V<TEntity>().AddV(model).FirstAsync();
Additional context
- This was working before and has suddenly stopped working and I can’t see any error or exceptions.
- I tried reverting my code to the old stage and still the same error.
- What I was doing was, I was storing non GraphSON documents on the CosmosDB alongside the usual GraphSON therefore I am using GremlinQ and ComsosDB SQL.NET API side-by-side. I was able to get it working last night but since today morning I’ve been seeing this error now with no idea how-to debug it. I thought I might’ve messed something in the CosmosDB so I’ve tried:
- Different containers (this doesn’t work), I get the same error.
- I tried creating a new vertices from gremlin via Web Portal, this works as expected.
I think my main issue is how-to debug this since I’m getting no error which I’d assume means that everything went alright so FirstAsync() should work.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Determine sequence contains no element using LINQ
Try var d = lst1.Where(q => q <= DateTime.Now).DefaultIfEmpty().Max();. Your result will now contain DateTime.MinValue if there are no ...
Read more >Sequence Contains No Elements: How To Solve the C# ...
Sequence contains no elements is an error in C# that arises when you use operators without taking into account an empty source. Click...
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. Sequence contains...
Read more >Source sequence doesn't contain any elements when ...
Updating my application gives the following error when there are no updates to download: System.InvalidOperationException: Source sequence ...
Read more >Fixing LINQ Error: Sequence contains no elements
When you get theLINQ Error “Sequence contains no elements”, this is usually because you are using the First() or Single() command rather ...
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 FreeTop 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
Top GitHub Comments
Note that there’s Gremlinq.*.AspNet packages that handle DI just fine. Even less documentation there though, but it’s all in the code and in the tests.
If you want to contribute, the Samples-Project could very well benefit from a second project that does the same but by utilizing the *.AspNet packages if you manage to figure things out from the code.
On first sight, you definitely want to register everything Gremlin as Singleton to avoid recreation on every query.