Type is an interface or abstract class and cannot be instantiated

Tags: #<Tag:0x00007fe1d952f3b0>

hi I am using InstaSharper ;
and when I login the program create an instance of InstaSharper

and I create job like this

IInstaApi in the above code that sent as parameter is instance of IInstaApi Interface (value has the same name with type :))

and i get this errore in dashboard
“”“Could not create an instance of type InstaSharper.API.IInstaApi. Type is an interface or abstract class and cannot be instantiated. Path ‘IsUserAuthenticated’, line 1, position 23.”""

before using HangFire I used Qurtz.net and haven’t any problem

I’ve faced the similar situation. The problem is that your method (AddFollowerState) uses IInstaApi interface as the type of argument. The problem here is that specific type is only known in run-time. Consider rewriting this method adding templated parameter so that type is known in the compile-time:

void F(ISomething x)
void F<T>(T x) where T : ISomething


the main problem is hangfire convert the value of parameter to JSON and its destroy object

1 Like

I believe it’s inevitable – Hangfire has to serialize method invocation somehow.


This worked like a charm. Thanks!!

I have a harder case…
The argument I have to serialize is List where each element of the list could be a different concrete implementation of IThingy. Even worse is that the job is defined in a project that can’t reference the concrete implementations of IThingy.

Any ideas?

Were you able to find any solution for this one?