logo
Tags down

shadow

A possible object cycle was detected which is not supported


By : daozhewrr
Date : September 15 2020, 05:00 AM
will be helpful for those in need _repo.GetRoles(); is not using await keyword
this var roles = _repo.GetRoles();
code :
  [HttpGet]
    public  async Task<IActionResult> Get()
    {
        var roles = **await** _repo.GetRoles();
        return new JsonResult(roles);
    }
public List<RoleMaster> GetRoles()
{
    try
    {
        var roles =  db.RoleMaster.AsNoTracking().ToList();
        return roles;
    }
    catch (Exception)
    {
        throw;
    }
}


Share : facebook icon twitter icon

A cycle in object graph detected in JPA


By : CoderOnStartups
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I suppose you are using some ORM to fetch data from database and then serialize it and send via web service. So when you fetch list of BlogGadgets they have Blogs in it, but the same Blogs have a list of the same BlogGadgets and so on...
Thats called circular reference and its very common to have them at your object model but when you want to send it on wire you need to make sure that object graph you have is a tree, at least for serializer you are using.
code :
[Serializable]
public class BlogGadgetDto 
{
  public int GadgetId {get;set;}
  public BlogSmallDto Blog {get;set;}
  // and so on
}

[Serializable]
public class BlogSmallDto 
{
  public int BlogId {get;set;}
  public string BlogName {get;set;}
  // and so on
}

JAXB A cycle is detected in the object graph


By : user2715820
Date : March 29 2020, 07:55 AM
it fixes the issue As you mentioned in your question EclipseLink MOXy (I'm the tech lead) has the @XmlInverseReference annotation to solve the problem of bidirectional relationships. As of EclipseLink 2.4 MOXy can produce/consume JSON.
For More Information

JAXB: A cycle is detected in the object graph


By : Jagrati Tak
Date : March 29 2020, 07:55 AM
With these it helps Your beans refer to each other: CategoryEntity.news contains at least one NewsEntity whose property categories contains the aforementioned CategroyEntity. Trying to output this as an XML would lead to an endless circle. Depending on what your "leading" Entity is you have to mark either categories or news as @XmlTransient.

.Net Core 3.0 possible object cycle was detected which is not supported


By : user3469901
Date : March 29 2020, 07:55 AM
seems to work fine I have tried your code in a new project and the second way seems to work well after installing the package Microsoft.AspNetCore.Mvc.NewtonsoftJson firstly for 3.0
code :
services.AddControllerWithViews()
    .AddNewtonsoftJson(options =>
    options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
);

JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the


By : antoniomtz
Date : March 29 2020, 07:55 AM
it helps some times In my web api when i run project for get data from database got this error .net core 3.1 , this is happening because your data have a reference loop.
e.g
code :
// this example creates a reference loop
var p = new Product()
     { 
        ProductCategory = new ProductCategory() 
           { products = new List<Product>() }
     };
    p.ProductCategory.products.Add(p); // <- this create the loop
    var x = JsonSerializer.Serialize(p); // A possible object cycle was detected ...
services.AddMvc()
     .AddNewtonsoftJson(
          options => {
           options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; 
      });
// if you not using .AddMvc use these methods instead 
//services.AddControllers().AddNewtonsoftJson(...);
//services.AddControllersWithViews().AddNewtonsoftJson(...);
//services.AddRazorPages().AddNewtonsoftJson(...);
// for manual serializer
var options = new JsonSerializerOptions
{
    ReferenceHandling = ReferenceHandling.Preserve
};

string json = JsonSerializer.Serialize(objectWithLoops, options);

// -----------------------------------------
// for asp.net core 3.1 (globaly)
 services.AddMvc()
  .AddJsonOptions(o => {
     o.JsonSerializerOptions
       .ReferenceHandling = ReferenceHandling.Preserve  
            });
public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string ProductText { get; set; }

    public int ProductCategoryId { get; set; }
    // [JsonIgnore] HERE or
    public virtual ProductCategory ProductCategory { get; set; }
}

public class ProductCategory
{
    public int Id { get; set; }
    // [JsonIgnore] or HERE
    public ICollection<Product> products {get;set;}
}
Related Posts Related Posts :
  • How to improve sqlite write performance in C#
  • c# add delay between concurrent task executions
  • timing a mutex,unsynchronized threads, and a semaphore in C#
  • Getting "Metadata generation failed" when building C# function app in Visual Studio 2019
  • Not all code paths return a value, how do I solve this?
  • How to solve the Proxy Server 407 error in .NET.CORE
  • Why doesn't [EnableCors("*", "*", "*")] allow all requests?
  • Ef core 3.0 gives error when inserting record 'The property 'Id' on entity type 'ChannelTypeT' could not be found'
  • How can I get access to the IWebHostEnvironment from within an ASP.NET Core 3 controller?
  • I have exported my data from grivdview to excel file now I want to save it directly on desktop through code how can I do
  • creating a method to find the sum of first and last Queue members
  • Dynamic connection string database c#
  • Open XML - find and replace multiple placeholders in document template
  • Name a complex type
  • Negating a Task<bool> without await?
  • Saving XML file “on the fly” in c#
  • C# - Async method in SELECT LINQ operation
  • Entity Framework : ChangeTracker loads all my table elements
  • Access public method from another namespace in Unity
  • My LIST of customers gets populated but will not display in my Foreach loop in Server Side Blazor
  • c# delete multiple data from database at once
  • Running a method forever while running other methods
  • How to tell Application to read <runtime> from my custom app.config file instead of from default one
  • System.TypeLoadException occurred when i try to compile
  • How to create class variable name dynamically in C#
  • How to deal with a massive amount of conditions
  • How to create complex dynamic queries in EF Core 3.1 after breaking changes?
  • WCF inactivityTimeout
  • How to get the digits before some particular word using regex in c#?
  • When other controls is placed inside datagrid column it is not binding
  • Connect to a SQL Server database in WPF C# (.exe) application from any PC
  • Get instance of singleton service in startup
  • Access controls located on the main form when the child form closes
  • C# Regex to match single number among multiple numbers in a string
  • C# regex string that is not another string
  • Pass Image object as a parameter from C# to Python
  • C# winform Two timers access same variable
  • What type of collection should be returned from EFCore 3.1 in WebAPI?
  • Don't repeat return values in C#8 switch syntax
  • How to speed up this LINQ query with join?
  • What is the best way to pass between scenes?
  • How do i play an animation on a button press
  • winform will Timer.timer create an new thread?
  • How to call async lamba expression with LINQ Select?
  • How to link IObservable and IObserver in C#?
  • How to leverage dynamic programming inside of a Linq Where clause?
  • Handling SQL Server errors separately from other types of exceptions
  • Proper way to update the list of records in table using entity framework
  • chunk file into pieces
  • why I can't get txtBox2.Text and txtBox3.Text value?
  • How can I use one function, which belongs to two objects, for only one objects?
  • I want string to contain specific charachers
  • multiply chars from array in C#
  • Load file as byte array with no allocate it in memory C#
  • how to make Wait until all threads finished it's work from threadpool in c#
  • How to: Project Architecture for Unity3D or Spaghetti code?
  • How to catch expander header button click event
  • How do you return 2 variables in C#/csharp?
  • can i update the private static dateTime each time the task runs (C# - quartz-scheduler)
  • C# string.this int ' cannot be assigned to (it is read-only) REPLACE
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk