Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UseTagsWithMongo error on startup #100

Open
gunsh opened this issue Dec 27, 2024 · 2 comments
Open

UseTagsWithMongo error on startup #100

gunsh opened this issue Dec 27, 2024 · 2 comments

Comments

@gunsh
Copy link

gunsh commented Dec 27, 2024

I have an existing Hangfire app. The thing I am missing the most is some sort of search capability. Somebody suggested to try Hangfire.Tags and so I did. I followed the instructions but I got the error below upon startup. I am not doing anything fancy. I have just added a call to UseTagsWithMongo. I don't see anything special in the provided sample code either. Using Hangfire.AspNetCore 1.8.17 and Hangfire.Mongo 1.11.2.

                var mongoStorageOptions = new MongoStorageOptions
                {
                    SupportsCappedCollection = supportsCappedCollection,
                    MigrationOptions = new MongoMigrationOptions
                    {
                        MigrationStrategy = new DropMongoMigrationStrategy(),
                        BackupStrategy = new NoneMongoBackupStrategy(),
                    },
                    CheckQueuedJobsStrategy = uri.Scheme == "mongodb" && supportsCappedCollection
                        ? CheckQueuedJobsStrategy.TailNotificationsCollection
                        : CheckQueuedJobsStrategy.Watch,
                    Prefix = "hangfire",
                    CheckConnection = true
                };

                // ....

                    .UseMongoStorage(
                        connectionString,
                        mongoStorageOptions
                    )
                    .UseTagsWithMongo(new TagsOptions() { TagsListStyle = TagsListStyle.Dropdown }, mongoStorageOptions);

And here is the error:

InvalidOperationException: Sequence contains no elements
System.Linq.ThrowHelper.ThrowNoElementsException()
System.Linq.Enumerable.Single<TSource>(IEnumerable<TSource> source)
MongoDB.Driver.IAsyncCursorExtensions.Single<TDocument>(IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken)
MongoDB.Driver.IAsyncCursorSourceExtensions.Single<TDocument>(IAsyncCursorSource<TDocument> source, CancellationToken cancellationToken)
MongoDB.Driver.IAggregateFluentExtensions.Single<TResult>(IAggregateFluent<TResult> aggregate, CancellationToken cancellationToken)
Hangfire.Tags.Mongo.MongoTagsServiceStorage.GetTagCount(JobStorage jobStorage, string setKey)
Hangfire.Tags.Storage.TagsStorage.GetTagsCount()
Hangfire.Tags.Dashboard.TagDashboardMetrics+<>c.<.cctor>b__1_0(RazorPage razorPage)
Hangfire.Dashboard.Pages.InlineMetric.Execute() in _InlineMetric.cshtml
Hangfire.Dashboard.RazorPage.TransformText(string body) in RazorPage.cs
Hangfire.Dashboard.RazorPage.ToString() in RazorPage.cs
Hangfire.Dashboard.HtmlHelper.RenderPartial(RazorPage partialPage) in HtmlHelper.cs
Hangfire.Dashboard.HtmlHelper.InlineMetric(DashboardMetric metric) in HtmlHelper.cs
Hangfire.Dashboard.Pages.SidebarMenu.Execute() in _SidebarMenu.cshtml
Hangfire.Dashboard.RazorPage.TransformText(string body) in RazorPage.cs
Hangfire.Dashboard.RazorPage.ToString() in RazorPage.cs
Hangfire.Dashboard.HtmlHelper.RenderPartial(RazorPage partialPage) in HtmlHelper.cs
Hangfire.Dashboard.HtmlHelper.JobsSidebar() in HtmlHelper.cs
Hangfire.Dashboard.Pages.QueuesPage.Execute() in QueuesPage.cshtml
Hangfire.Dashboard.RazorPage.TransformText(string body) in RazorPage.cs
Hangfire.Dashboard.RazorPage.ToString() in RazorPage.cs
Hangfire.Dashboard.RazorPageDispatcher.Dispatch(DashboardContext context) in RazorPageDispatcher.cs
Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext) in AspNetCoreDashboardMiddleware.cs
Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
@erwin-faceit
Copy link
Contributor

The sample dashboard first launches a few tasks, but when I remove these, and start with an empty Mongo database, I get the exact same result. So I'm guessing that your database also doesn't have any tags yet.

I've just made a change to the code, give it some time, and NuGet will show version 1.9.1 which should fix this issue.

@gunsh
Copy link
Author

gunsh commented Dec 30, 2024

Yes, you are right. My db had no tags but I expect this to be the default for anyone adopting your library. Anyway, your fix did work and now I see "Tags" in the Hangfire left-hand menu. Thanks for fixing this.

Still, when I navigate to "Tags", I get a MongoDB load error:

      System.IO.FileNotFoundException: Could not load file or assembly 'MongoDB.Driver.Core, Version=2.19.2.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
      File name: 'MongoDB.Driver.Core, Version=2.19.2.0, Culture=neutral, PublicKeyToken=null'
         at Hangfire.Tags.Mongo.MongoTagsServiceStorage.SearchWeightedTags(JobStorage jobStorage, String tag, String setKey)
         at Hangfire.Tags.Storage.TagsStorage.SearchWeightedTags(String tag)
         at Hangfire.Tags.Dashboard.Pages.TagsSearchPage.Execute()
         at Hangfire.Dashboard.RazorPage.TransformText(String body) in C:\projects\hangfire-525\src\Hangfire.Core\Dashboard\RazorPage.cs:line 179
         at Hangfire.Dashboard.RazorPage.ToString() in C:\projects\hangfire-525\src\Hangfire.Core\Dashboard\RazorPage.cs:line 103
         at Hangfire.Dashboard.RazorPageDispatcher.Dispatch(DashboardContext context) in C:\projects\hangfire-525\src\Hangfire.Core\Dashboard\RazorPageDispatcher.cs:line 38
         at Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext) in C:\projects\hangfire-525\src\Hangfire.AspNetCore\Dashboard\AspNetCoreDashboardMiddleware.cs:line 99
         at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)

I am on the latest MongoDB 3.1.0 and your library seems to use 2.19.2. The two don't seem to be compatible. I have tried upgrading your sample to use MongoDB 3.1.0 just to see what happens but I get build errors.

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants