Type is an interface or abstract class and cannot be instantiated

recurring
Tags: #<Tag:0x00007f7832656038>

#1

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


#2

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)
vs
void F<T>(T x) where T : ISomething


#3

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


#4

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


#5

Eugene,

This worked like a charm. Thanks!!


#6

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?