.NET CORE 3.1 - getting Cannot read property 'length' of undefined - Urgent
.NET CORE 3.1 - getting Cannot read property 'length' of undefined - Urgent

I migrated a working project from .net core 2.1 to 3.1 and I am now receiving this error from: jquery.dataTables.min.js
Uncaught TypeError: Cannot read property 'length' of undefined
I am fetching data from the database successfully but displaying it is causing this error.
I tried with both DataTables Editor v1.9.0 and DataTables Editor v1.9.2 and with both DataTables-1.10.19 and DataTables-1.10.20
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
That normally happens when the Ajax isn't correct - either badly formatted or the number of columns doesn't match what's configured for the table. That would be the place to start.
Colin
@colin Its weird since it's the same code, nothing was changed but the Migration to .Net Core 3.1, i will further investigate and post my findings if i get this resolved
The issue was from my side!
I forgot to add:
services.AddControllers().AddNewtonsoftJson();
in Startup.cs for .Net Core 3.1
After adding that, everything went back to normal.
I just came across this issue during my migration to 3.1. As soon as I migrated to asp.net core 3.1 all of my datatables stopped working. I guess their default is now System.Text.Json vs. Newtonsoft. Is there a way to use System.Text.Json? I'm not 100% sure that's my problem but I'll go ahead and load newtonsoft and see if that fixes things.
https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#newtonsoftjson-jsonnet-support
Update - Yup, that fixed my datatables. I'm glad I saw your post, no telling how long I would've had to diagnose that one.
The question still stands though, if .net core is using another default I'd rather use that than having to load a dependency. Let me know your thoughts.
Thanks marcasmar94!
We don't actually reference Newtonsoft in our library - it's the controller (or perhaps more specifically the controller's framework) that uses it. Did you update your Nuget packages when switching over to 3.1?
Allan
Yes I did and still no go. Datatables blank. We use them a lot and every one of them came up with no results. I switch back to asp.net core 2.2 pointed at the same database, fine. Switching back to 3.1, blank. No errors. I added newtonsoft package in (because you have to do that manually now with 3.x) and added the services line into my startup.cs that marcasmar94 mentioned and everything was pulling in data just fine. Normal after that. Magic.
Same results on my home and work computer. DT pulls in results and Editor works just fine making changes.
Thanks for the results of your investigation. I've filed a bug to get this looked at and hopefully resolved for the next patch release of Editor. Until then, the Newtonsoft inclusion workaround seems to be the way to go.
Regards,
Allan
Just an update to say this has been resolved and will appear in the next version of Editor (1.9.3) due out later this week.
Colin
edited - 1.9.3 is the next release rather than 1.7.3
OMG, thanks for this post. The Editor 1.9.3 update did not fix the problem but adding the
services.AddControllers().AddNewtonsoftJson();
fixed the problem.
NewtonsoftJson is does something different compared to System.Text.Json. My Json DtReponse populates data but on xhr inspection, my model would always be blank.
Is anyone able to get this to work in a production (not localhost) environment? I'm using editor 1.9.4 and my jquery API calls all return no data and never reach the endpoint. It works fine in localhost with kestrel but not when deployed to IIS server.
Never mind on my last comment. Figured it out.