# Cannot create an instance of an interface on Asp.net Console app

**URL:** <https://discuss.hangfire.io/t/cannot-create-an-instance-of-an-interface-on-asp-net-console-app/10858>\
**Category:** bug?\
**Tags:** aspnetcore\
**Created:** [August 16, 2024, 6:36am UTC](https://discuss.hangfire.io/t/cannot-create-an-instance-of-an-interface-on-asp-net-console-app/10858 "2024-08-16T06:36:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![code](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/code/32/3783_2.png) [@code](https://discuss.hangfire.io/u/code)\
**Post date:** [August 16, 2024, 6:36am UTC](https://discuss.hangfire.io/t/cannot-create-an-instance-of-an-interface-on-asp-net-console-app/10858/1 "2024-08-16T06:36:22Z")

</div>

I am using Microsoft.Extensions.Hosting

Right now using following code on program.cs

```auto
    serviceCollection.AddHangfire((provider, globalConfig) =>
            {
                globalConfig
                .SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
               .UseColouredConsoleLogProvider()
               .UseSimpleAssemblyNameTypeSerializer()
               .UseRecommendedSerializerSettings()
               .UseDefaultActivator()
               .UseSqlServerStorage(context.Configuration.GetConnectionString("QuantumEComDbContext"));

            });

           

           JobStorage.Current = new SqlServerStorage(context.Configuration.GetConnectionString("QuantumEComDbContext"));

```

My Test Code

```auto
   public class TestJob:ITestJob
    {
        private readonly ILogger _logger;

        //public TestJob()
        //{

        //}

        public TestJob(ILogger<TestJob> logger) => _logger = logger;
            
        public void WriteLog(string logMesage) {
            _logger.LogInformation($"Tets job");
        
        }
    }

    public interface ITestJob
    {
        void WriteLog(string logMesage);
    }

```

Calling from another class

```auto
 foreach (var store in stores.Take(2))
        {
                       BackgroundJob.Enqueue<ITestJob>(x => x.WriteLog("test"));
        }

        using (var server = new BackgroundJobServer())
        {
            Console.ReadLine();
        }

```

But when running code getting following error.

```auto
024-08-16 11:50:22.7085 | WARN | Hangfire.AutomaticRetryAttribute | Failed to process the job '2': an exception occurred. Retry attempt 1 of 10 will be performed in 00:00:19.
System.MissingMethodException: Cannot dynamically create an instance of type 'Process.ITestJob'. Reason: Cannot create an instance of an interface.
   at System.RuntimeType.ActivatorCache..ctor(RuntimeType rt)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at Hangfire.JobActivator.ActivateJob(Type jobType) in C:\projects\hangfire-525\src\Hangfire.Core\JobActivator.cs:line 48
   at Hangfire.JobActivator.SimpleJobActivatorScope.Resolve(Type type) in C:\projects\hangfire-525\src\Hangfire.Core\JobActivator.cs:line 82
   at Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext context) in C:\projects\hangfire-525\src\Hangfire.Core\Server\CoreBackgroundJobPerformer.cs:line 60

```

---

<div class="post-metadata">

**Author:** ![apatel\_sepire](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/apatel_sepire/32/3814_2.png) [@apatel\_sepire](https://discuss.hangfire.io/u/apatel_sepire)\
**Post date:** [September 18, 2024, 8:24pm UTC](https://discuss.hangfire.io/t/cannot-create-an-instance-of-an-interface-on-asp-net-console-app/10858/2 "2024-09-18T20:24:19Z")

</div>

Did you ever get a response to this? We’re getting a similar vague error with reoccurring tasks too, and trying to figure out where it came from so randomly.
