sirkris / Reddit.NET

A Reddit API library for .NET Standard with OAuth support. Written in C#.
MIT License
508 stars 78 forks source link

JsonSerializationException #149

Closed IsaaacD closed 2 years ago

IsaaacD commented 2 years ago

When I try to access RedditClient.Account.Me I get the following issue image Is this something that has changed? I was using the Nuget package and it stopped working today, I've been playing with it for a few weeks without issue.

Please advise

The error reads: 'Error converting value {null} to type 'System.Boolean'. Path 'subreddit.user_is_muted', line 1, position 477.'

IsaaacD commented 2 years ago

If I change UserSubreddit.cs line 32 to have a nullable boolean it works public bool? UserIsMuted { get; set; }

GamingWolf commented 2 years ago

For those that need it working now and don't really now how:

  1. Pull this repo
  2. Open the Reddit.NET solution
  3. Navigate towards Things/User/UserSubreddit.cs
  4. Change public bool UserIsMuted to public bool? UserIsMuted (i.e. make it nullable)
  5. Build the soltion (Maybe also increment the version to indicate this fix)
  6. Copy the .nupkg file that gets created to a location you can remember (you can find it in Reddit.NET\bin\Debug)
  7. Add the folder you placed the file in to your NuGet.config (usually found in C:\Users\$USER\AppData\Roaming\NuGet\
  8. Add this key <add key="Local Source" value="Path\To\Folder" />
  9. Make sure your application actually pulls Reddit.NET from the local source
  10. Compile and wait for the official fix
IsaaacD commented 2 years ago

It might be worth considering making all the types nullable incase something like this pops up for other properties

sirkris commented 2 years ago

@IsaaacD Yeah I've gone back and forth on this one. I really want the properties to map to their API counterparts as closely as possible (especially in the Models/Things layer). So if a user sees a property that's nullable, they'll know at a glance that the API can return null for that field.

The main problem I see with making everything nullable is that it makes the userland code needlessly clunky. I mean, to have hundreds of nullable types just because one of them might be changed to nullable every couple years just doesn't seem to pass the cost-benefit test for me.

The real issue here isn't the nullables. The issue is with me and my apparent slowness to respond to these kinds of issues as of late. I'm hoping this will get better as my schedule gets a little more manageable. SLA on core-breaking hotfixes should not be measured in weeks, so that one's on me.

sirkris commented 2 years ago

PR #150 has been merged into develop.

IsaaacD commented 2 years ago

@sirkris yea that makes sense, I've only been using the project for a couple weeks and didn't put much thought into it in except that having Reddit shift their API responses could be messy. That makes sense to keep the API clean and intuitive, I'm not sure how often Reddit plans to make such changes.

sirkris commented 2 years ago

I went ahead and put out a hotfix release. If you update to version 1.5.2 in NuGet, the library should work again.