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;
});
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
Most helpful comment
Are you looking for
JobHelper.SetSerializerSettings()?