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

Issues with .NetCore 3.1 #85

Open
InvincibleDRT opened this issue Sep 28, 2021 · 4 comments
Open

Issues with .NetCore 3.1 #85

InvincibleDRT opened this issue Sep 28, 2021 · 4 comments

Comments

@InvincibleDRT
Copy link

I am getting following errors when migrating to 3.1 from 2.2

`Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.

Could not load type 'Microsoft.AspNetCore.Http.Authentication.AuthenticationManager' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=3.1.19.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Could not load type 'Microsoft.AspNetCore.Http.Authentication.AuthenticateInfo' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=3.1.19.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Could not load type 'Microsoft.AspNetCore.Http.Features.Authentication.ChallengeBehavior' from assembly 'Microsoft.AspNetCore.Http.Features, Version=3.1.19.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)

at System.Reflection.RuntimeModule.GetTypes()

at System.Reflection.Assembly.GetTypes()

at Hangfire.RecurringJobAdmin.PeriodicJobBuilder.GetAllJobs()

at Hangfire.RecurringJobAdmin.ConfigurationExtensions.UseRecurringJobAdmin(IGlobalConfiguration config, Boolean includeReferences, Assembly[] assemblies)
`

@YanerTavuz
Copy link

Have you tried cleaning the solution before rebuilding? Also delete the bin/obj folders.

@InvincibleDRT
Copy link
Author

Yeah i tried a fully clean and published version also. same result. Not sure if the support was added for 3.1

@YanerTavuz
Copy link

Well, since the targeted frameworks are NET Standard 2.0 and NET Framework 4.6.2, it should be supported.

@SerbanApostol
Copy link

It might be due to trimming of unused types on publish or maybe some other reason. The "cause" is that all assemblies are scanned to look for a custom attribute: Hangfire.RecurringJobAdmin.RecurringJobAttribute. One solution is to tell this library exactly what assemblies to look into when adding it to your services (if you use dependency injection and ASP.NET Core; look for the functions with similar signatures):

public static IGlobalConfiguration UseRecurringJobAdmin(this IGlobalConfiguration config, bool includeReferences = false, [NotNull] params Assembly[] assemblies);

Call example:

using Hangfire;
using Hangfire.RecurringJobAdmin;
using Hangfire.Server;
using Hangfire.SqlServer;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Reflection;

static IServiceCollection AddHangfireCustom(this IServiceCollection services, string dbConnectionString)
{
    services.AddHangfire(x => x.UseSqlServerStorage(dbConnectionString)
        .UseRecurringJobAdmin(new Assembly[] { typeof(Startup).Assembly, typeof(PerformContext).Assembly }));
    return services;
}

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

3 participants