Hangfire: Self referencing loop issue in ASP.NET Core

Created on 1 Jan 2017  路  7Comments  路  Source: HangfireIO/Hangfire

I have Self referencing loop detected for property 'X' with type 'Y'. Path 'Z' issue. is there any way to handle this issue globally instead of putting [JsonIgnore] attribute every where, something like this:

services.AddHangfire(options => { 
    options.UseSqlServerStorage(configuration["ConnectionStrings:HangfireConnection"]); 
    options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
question

Most helpful comment

Are you looking for JobHelper.SetSerializerSettings()?

All 7 comments

Are you looking for JobHelper.SetSerializerSettings()?

How can we use JobHelper.SetSerializerSettings() in .Net Core 2.0?

Just realised this is a static class :)

I had trouble figuring out how to implement these settings, so in case anyone else is also wondering, this is what my startup.cs looked like once I added code:

services.AddHangfire(options =>
{ 
  options.UseSqlServerStorage(configuration["ConnectionStrings:HangfireConnection"]); 
});

JobHelper.SetSerializerSettings(new JsonSerializerSettings
{
  ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});

Happy coding!

SetSerializerSettings() from JobHelper is now obsolete. Use GlobalSettings instead:

GlobalConfiguration.Configuration.UseSerializerSettings(new JsonSerializerSettings
{
    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
});

[DotNet Core 3.1]

I have the following settings

'''
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(Configuration.GetConnectionString("CronJob"))
.UseSerializerSettings(new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
}));
'''

It worked.

I got the same error on Core 3.1

I used .UseRecommendedSerializerSettings().

I changed it to .UseRecommendedSerializerSettings(settings => settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore));

Perhaps this should be the Recommended setting for .NET Core 3.1 ?

@odinserj Is this a common problem for Core 3.1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shorbachuk picture shorbachuk  路  4Comments

osmanrahimi picture osmanrahimi  路  3Comments

odinserj picture odinserj  路  4Comments

cindro picture cindro  路  3Comments

jeffsugden picture jeffsugden  路  4Comments