Serialize AnonymousType

On of my job keeps failing due to on of the parameters are an AnonymousType. Does hangfire doesn’t suppport AnonymousTypes?

Trigger Job:

_jobClient.Enqueue( logger =>
logger.CreateLog(“username”, “log Type”, new {
Message = “test”
}));

Hangfire Error:

Newtonsoft.Json.JsonSerializationException

Error converting value “<>f__AnonymousType19`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=]], App.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null” to type ‘System.Type’. Path ‘[2]’, line 1, position

Using anonymous types is a way to screw up royally, as they don’t guarantee binary compatibility between method signatures. Just changing some method’s implementation might cause new anonymous types added or old ones removed, resulting in all the anonymous types in your assembly to receive different numbers. For this reason they’re not suitable for serialization/deserialisation.