Results 1 to 5 of 5

Thread: Question about Newtonsoft.Json

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Question about Newtonsoft.Json

    Please move if this is the wrong section. Also, my apologies for how long this is going to be.

    We have an in-house C# Windows program that runs the company's daily activities.
    We use asana for project management.
    There is an asana API so my C# code can interface with asana.
    It was using Newtonsoft to process json. This is not my area of expertise so forgive me if I don't describe everything correctly, and feel free to correct me.
    We have another smaller application, also C# Windows program that users want the same "send to asana" function replicated. So while familiarizing myself with this functionality (it's been untouched for years since I developed it), I got an exception "the application has received an unexpected response from asana. The Response is Cannot convert object of type System.Int32 to type asanaAPI.RootObject." So ok, I was going to see what that was. WHen I opened the module in VS 2022, Newtonsoft was red and it says "does not exist in the current context". I googled "What happened to Newtonsoft" and I guess it's replaced.

    So, what does that mean for my non-working code? If I change the code I can't rebuild but if I leave it alone it runs fine. Which I guess is good; I haven't blown my users out of the water.

    So I will look into how to replace Newtonsoft with System.Text.Json because I guess I have to.

    Do you have any words of wisdom to share? (Because I realize I haven't really asked a question that I'm not going to try to answer myself ). Thanks.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,672

    Re: Question about Newtonsoft.Json

    Newtonsoft is still available but you are correct in that they deprecated it in favor of System.Text.Json.

    The error you are receiving is because somewhere in your code it is attempting to convert an integer value to an instance of your RootObject class and you cannot do that, at least not implicitly.

    Without seeing your code, I cannot say for certain but what I suspect is happening is that it is attempting to deserialize the JSON to an integer value and assign it to a variable that's been defined as a RootObject.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Question about Newtonsoft.Json

    OK but the odd thing about the exception is that code hasn't been touched in years so I'm not sure what would cause it. Of course, it could be something about the asana notes on that particulate entity (we call them cases/jobs). Maybe it's different data than what I've gotten back in the past.
    Additionally, and you might've missed this in my rambly post: WHen I opened the module in VS 2022, Newtonsoft was red and it says "does not exist in the current context". So I can't make any changes to that code; it won't rebuild.
    HOWEVER, my boss said no one is using notes anymore! I am not going to work fixing something no one uses. (Things change around here often. I get asked for things then I get asked to take away those things).
    So I guess for now I am not working on this, though feel free to keep the discussion going. Or not. And thanks for the reply!
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,672

    Re: Question about Newtonsoft.Json

    Could it be possible that you recently upgrade the version of .NET in the project?

    Regardless, I would definitely suggest doing a Clean and then a Build on the project.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Question about Newtonsoft.Json

    While Microsoft is leaning towards System.Text.Json and I'm guessing you are not moving to .NET Core or 8 . Have you tried adding the Newtonsoft Nuget Package again?
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width