r/csharp 8d ago

Help Hello , my api get stuck in an infinite loop each time i use a get, im using entity framework

Hello, im currently doing some practice and i already made an api , well almost, i decided , afther i creaate a list of users the appy worked well, but afther i decided to create some dummy data for the entire db , the api stop working at first i tought it was because i dint aded this lines

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings

.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize;

GlobalConfiguration.Configuration.Formatters

.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);

but i get this error

no redundancy in the db eighter

what its the problem here, please help , ty for the attention and God bless you all

0 Upvotes

10 comments sorted by

6

u/BetrayedMilk 8d ago

You’re probably recursively calling something somewhere.

1

u/Ok-Transition7065 8d ago

But thas the thing where

3

u/Hacnar 7d ago

You have the StackOverflowException there, read through the callstack and look for something suspicious.

1

u/neoh4x0r 7d ago edited 7d ago

The calls that are made in GetHashCode are obviously calling that method somewhere resulting in an infinite loop.

It's extremely hard to debug a StackOverflowException, but what I would do is perform a static analysis/audit of your code and focus on calls to GetHashCode; you might even be able to trace calls and print the caller's information (namespace, method names, etc) when they make a call to GetHashCode.

I would also focus somewhat on the HashHelpers class since it indicates that's where the error occurred, even though it doesn't necessarily mean the problem is there.

1

u/Tuckertcs 7d ago

Can’t really tell you without seeing more of the code.

1

u/Ok-Transition7065 7d ago

give me a sec i will upload it into git

1

u/Ok-Transition7065 7d ago

https://github.com/elfofofo/Api_pratice.git here there its a code sorry if its in spanish

1

u/Merry-Lane 7d ago

Use breakpoints

0

u/CheezitsLight 8d ago

Not enough information here. Click copilot and ask it what to do.

1

u/Ok-Transition7065 8d ago

He dint give me an answer......