Hangfire FileNotFoundException:无法加载文件或程序集DynamicProxyGenAssembly,

时间:2016-10-12 05:36:57

标签: c# asp.net hangfire

我在设置后台作业后遇到HangFire的问题但是当我打开HangFire仪表板时,我看到以下例外

  

System.IO.FileNotFoundException:无法加载文件或程序集   'DynamicProxyGenAssembly2,Version = 0.0.0.0,Culture = neutral,   PublicKeyToken = null'或其依赖项之一。系统不能   找到指定的文件。

使用AutoFac for DI注册所有接口。 ,我在startup.cs中设置了以下内容

我在启动时有以下代码

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

我有以下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);
    }
}

正在调用的代码在这里

 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);
      }
    }

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

可能与你的背景不同,但我认为它仍然值得在这里添加:
-Hangfire服务器作为Windows服务运行;
-Hangfire仪表板在ASP.NET MVC 5应用程序之上运行;
-jobs实际上正在运行,但仪表板一直显示FileNotFoundException;

解决方案:在信息中心网页应用中添加了对缺少的程序集的引用(即:&#39; DynamicProxyGenAssembly2&#39;)。

@reggieboyYEAH以同样的方式报告并解决了同样的问题 详情请见https://github.com/HangfireIO/Hangfire/issues/558

答案 2 :(得分:0)

我也有同样的问题。但我尝试将包含'BackgroundJob.Enqueue'的方法移动到vm类。当我想调用这个方法时。我将新建一个vm课程。然后使用vm调用该方法。这将是成功的。我认为原因是一些资源被两个对象同时使用。无论如何它可以运行。我希望这可以帮助你。

我的例外情况如下

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&amp; 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  (完全指定的) 日志:Appbase = file:/// D:/ Code / Test / bin / Debug / net461 / 日志:初始PrivatePath = NULL

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

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

相关问题