Hangfire FileNotFoundException: Could not load file or assembly DynamicProxyGenAssembly,

倖福魔咒の 提交于 2020-01-05 04:19:27

问题


I am having an issue with HangFire after i set a background job it get set but when i open the HangFire dashboard i see the following exception

System.IO.FileNotFoundException: Could not load file or assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

All interfaces are being registered using AutoFac for DI. , I am setting up the following in the startup.cs

I have the following code in the startup

  GlobalConfiguration.Configuration.UseSqlServerStorage("Hangfire");
  app.UseHangfireDashboard();
  app.UseHangfireServer();

I have the following ocde to schule the job

 public class ScheduleAppService : IScheduleAppService
  {
    private readonly IRunCommandAppService _runCommandAppService;

    public ScheduleAppService(IRepository<Schedule> repository, IAdHocTemplateRunnerAppService adHocTemplateRunner) : base(repository)
    {
      _adHocTemplateRunner = adHocTemplateRunner;
    }

    public async Task CreateSchedule(ScheduleDto schedule)
    {
      input.Schedule.JobId = BackgroundJob.Schedule(
        () => _runCommandAppService.AddTemplate(
          new Template{ RunId = Guid.NewGuid().ToString(), TemplateId = schedule.Id }), schedule.Start);
    }
}

The code which is being called is here

 public class RunCommandAppService  : IRunCommandAppService 
  {
    private readonly IRepository<Template> _templateRepo;

    public RunCommandAppService (IRepository<Template> templateRepo)
    {
      _templateRepo = templateRepo;
    }

    public void AddTemplate(Template input)
    {
      try
      {
        Run(input);
      }
      finally
      {
        SetRunComplate(input.RunId);
      }
    }

回答1:


input.Schedule.JobId = BackgroundJob.Schedule<IAdHocTemplateRunnerAppService >(
            x =>
                x.AddTemplate (new Template{ RunId = Guid.NewGuid().ToString(), TemplateId = schedule.Id }), input.Schedule.Start);



回答2:


Might not be the same context as yours but I think it's still worth adding it here:
-Hangfire server was running as a Windows service;
-Hangfire dashboard running on top of a ASP.NET MVC 5 app;
-jobs were actually running but dashboard kept displaying a FileNotFoundException;

Solution: added a reference to the missing assembly (ie: 'DynamicProxyGenAssembly2') in the dashboard web app.

Same problem was reported and solved in the same way by @reggieboyYEAH.
Details here: https://github.com/HangfireIO/Hangfire/issues/558




回答3:


I also have same issue. But I try to move the method which contains ' BackgroundJob.Enqueue ' to a vm class . When I want to call this method . I will new a vm class . Then use vm to call the method . It will be success . I think the reason is some resource is used by two object in the same time. Anyway it can run .I hope this can help you.

My exception is like below

warn: Hangfire.AutomaticRetryAttribute[0]
  Failed to process the job '15': an exception occurred. Retry attempt 3 of 10 will be performed in 00:01:01.

`System.IO.FileNotFoundException: 未能加载文件或程序集“DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。系统找不到指定的文件。 文件名:“DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null” 在 System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) 在 System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) 在 System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) 在 Hangfire.Storage.InvocationData.Deserialize()

=== 预绑定状态信息 === 日志: DisplayName = DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified) 日志: Appbase = file:///D:/Code/Test/bin/Debug/net461/ 日志: 初始 PrivatePath = NULL

调用程序集: Hangfire.Core, Version=1.6.19.0, Culture=neutral, PublicKeyToken=null。`

日志: 此绑定从 default 加载上下文开始。 日志: 正在使用应用程序配置文件: D:\Code\Test\bin\Debug\net461\ Test.exe.Config 日志: 使用主机配置文件: 日志: 使用 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config 的计算机配置文件。 日志: 此时没有为引用应用策略(私有、自定义、分部或基于位置的程序集绑定)。 日志: 相同的绑定已出现过,因 hr = 0x80070002 而失败。



来源:https://stackoverflow.com/questions/39991196/hangfire-filenotfoundexception-could-not-load-file-or-assembly-dynamicproxygena

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!