JsonConvert.DeserializeObject and DataSourceResult

1 Answer 643 Views
General Discussions Grid
Fred
Top achievements
Rank 1
Iron
Fred asked on 19 May 2021, 11:49 PM

Hi,

I'm stuck trying to return a DataSourceResult from an API and deserialize it using JSONConvert.DeserializeObject<DataSourceResult>(json)

This is what I am doing on the ASP.NET Core API side using a DataSourceRequest as input.

                DataSourceResult result = await _repo.Internments.ToDataSourceResultAsync(dsRequest);

                return new ContentResult() {
                        StatusCode = StatusCodes.Status200OK,
                        ContentType = "application/json",
                        Content = JsonConvert.SerializeObject(result, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All })
                    };

Then I am trying to deserialize it on the receiving end (HttpResponseMessage) in an ASP.NET Core MVC controller for use in a grid:

                string funcJSON = getResponse.Content.ReadAsStringAsync().Result;
                result = JsonConvert.DeserializeObject<DataSourceResult>(funcJSON, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All } );

An exception is generated when I try to deserialize it. The assembly is there. Not sure what I am doing wrong.

"Error resolving type specified in JSON 'Telerik.DataSource.DataSourceResult, Telerik.DataSource'. Path '$type', line 1, position 66."

 

Any help is appreciated.  Thanks!

Fred
Top achievements
Rank 1
Iron
commented on 20 May 2021, 03:45 AM

Ugg! Fixed my own issue. Found out I had a mismatch in packages between two projects causing the namespace mismatch.

1 Answer, 1 is accepted

Sort by
0
Fred
Top achievements
Rank 1
Iron
answered on 20 May 2021, 03:47 AM
Removed the Telerik.DataSource package that didn't match the Telerik UI for ASP.NET Core that was in the other project. I installed this package in its place. Once the namespaces matched the JSON deserialization worked. It was my own fault.
Tags
General Discussions Grid
Asked by
Fred
Top achievements
Rank 1
Iron
Answers by
Fred
Top achievements
Rank 1
Iron
Share this question
or