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

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

marcasmar94marcasmar94 Posts: 9Questions: 3Answers: 1

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

Answers

  • colincolin Posts: 8,013Questions: 0Answers: 1,348

    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

  • marcasmar94marcasmar94 Posts: 9Questions: 3Answers: 1

    @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

  • marcasmar94marcasmar94 Posts: 9Questions: 3Answers: 1
    Answer ✓

    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.

  • dhutton@creativeone.comdhutton@creativeone.com Posts: 55Questions: 14Answers: 0

    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

  • dhutton@creativeone.comdhutton@creativeone.com Posts: 55Questions: 14Answers: 0
    edited February 12

    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!

  • allanallan Posts: 51,411Questions: 1Answers: 7,752 Site admin

    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

  • dhutton@creativeone.comdhutton@creativeone.com Posts: 55Questions: 14Answers: 0

    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.

  • allanallan Posts: 51,411Questions: 1Answers: 7,752 Site admin

    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

Sign In or Register to comment.