Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Unable to use hangfire. Getting following exception #1340


User avatar
0
shyamjith created

WARN 2016-06-29 14:33:12,459 [duler] Hangfire.AutomaticRetryAttribute - Failed to process the job '9': an exception occurred. Retry attempt 5 of 10 will be performed in 00:04:36. 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. File name: 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) at Hangfire.Storage.InvocationData.Deserialize()


6 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you share your code which causes this exception ? And where do you use that code ? In test project or your web/windows project ?

  • User Avatar
    0
    shyamjith created

    I am using hangfire in inside my web project.

    // inside my controller i have added these lines 
     RecurringJob.RemoveIfExists("Job1");
      RecurringJob.AddOrUpdate("Job1", () => Job1(), Cron.Daily(11, 47));
    
     public void Job1()  {
    
    //Do some job
    }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Instead of using method of controller, you should create a new class and call it's method for your recurring job.

  • User Avatar
    0
    shyamjith created

    When i tried that i am getting another exception

    Castle.MicroKernel.ComponentNotFoundException

    No component for supporting the service RentMoji.Web.BackGroundJobs was found

    Castle.MicroKernel.ComponentNotFoundException: No component for supporting the service RentMoji.Web.BackGroundJobs was found at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) at Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments) at Castle.Windsor.WindsorContainer.Resolve(Type service) at Abp.Dependency.IocManager.Resolve(Type type) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Dependency\IocManager.cs:line 194 at Abp.Hangfire.HangfireIocJobActivator.ActivateJob(Type jobType) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.HangFire\Hangfire\HangfireIocJobActivator.cs:line 24 at Abp.Hangfire.HangfireIocJobActivator.HangfireIocJobActivatorScope.Resolve(Type type) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.HangFire\Hangfire\HangfireIocJobActivator.cs:line 48 at Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext context) at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass8_0.<PerformJobWithFilters>b__0() at Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter, PerformingContext preContext, Func1 continuation) at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass8_1.<PerformJobWithFilters>b__2() at Hangfire.Server.BackgroundJobPerformer.PerformJobWithFilters(PerformContext context, IEnumerable1 filters) at Hangfire.Server.BackgroundJobPerformer.Perform(PerformContext context) at Hangfire.Server.Worker.PerformJob(BackgroundProcessContext context, IStorageConnection connection, String jobId)

    Here is my Code

    public class BackGroundJobs:IBackGroundJobs
        {
          
            public void AddJob1()
            {
                RecurringJob.RemoveIfExists("Job1");
                RecurringJob.AddOrUpdate("Job1", () => Job1(), Cron.Daily(11, 47));
            }
            public void Job1()
            {
                DependencyResolver.Current.GetService<ISubscriberAppService>().SendEmailToSubscribers();
            }
    
        }
    
  • User Avatar
    0
    hikalkan created
    Support Team

    Do not use controller methods for jobs since controller types are proxied and dynamically generated on the fly. It can not be re-created via reflection. I prepared a Gist for you: <a class="postlink" href="https://gist.github.com/hikalkan/d543b6ded179d1f05227f49bc70e2fbe">https://gist.github.com/hikalkan/d543b6 ... 9bc70e2fbe</a> I tested, it's properly working.

  • User Avatar
    0
    shyamjith created

    Thank you, It worked .

    Thanks ismcagdas and hikalkan