All Questions
46 questions
0
votes
2
answers
475
views
System.Text.Json: Sort by key Hashtable?
I am serializing my object using a simple:
var options = new JsonSerializerOptions { WriteIndented = true, IncludeFields = true};
string jsonString = JsonSerializer.Serialize(obj, options);
File....
0
votes
1
answer
607
views
Can't return multiple object on asp.net core web api
I can't return an integer and an IEnumerable from my Web API. IEnumerable has vm classes.
This is Response.cs:
using System.Collections.Generic;
using TheMPDB_API.DataClasses;
namespace TheMPDB_API....
1
vote
0
answers
900
views
.Net 5 Web Api, default System.Text.Json serialization is replaced by Newtonsoft.Json without specifying in startup.cs
How to avoid System.Text.Json to be replaced by Newtonsoft.Json, when send response from controller. When i testing my application i found json serialized by Newtonsoft.Json without specifying any ...
2
votes
1
answer
3k
views
.NET 5 - Json Serialization with comma as decimal separator
Is there a way to serialize a JsonResult in a controller considering the current locale?
In my case when the language is set to italian I wish separator for decimal values was ',' instead of '.'.
...
1
vote
1
answer
1k
views
.net5 secrets.json not being used locally
I have a .net5 web app in which I am trying to add a secrets.json file so I have right clicked and created the file - in my project file I can see:
<PropertyGroup>
<TargetFramework>net5....
0
votes
1
answer
966
views
Deserializing to an object and an array of objects using RestSharp
I have an API, that either returns an object1 with Status code Ok or an array of object2 that contains error messages with Status code that is not Ok.
For eg:
Case of good response:
{
"...
-1
votes
2
answers
111
views
How to modify value of a property in a json text in C#?
I have a service that receives some data with random structure in JSON format and persists these data in a document-based database. I have no control over sending services and there are some sensitive ...
2
votes
0
answers
445
views
How to send large json data with Jquery Ajax Post in .NET 5
I have data in Razor page then i want to send data to MVC Action with jquery as this.
$("#SaveData").click(function (e) {
e.preventDefault();
var _models = new Array();
...
0
votes
1
answer
474
views
How to Exclude Fields from Navigation Property
I am trying to learn .NET 5 with using ASP.NET Core 5. These days I am working on a blog project that developing with ASP.NET Core 5 MVC & NLayer architecture. This project uses Entity Framework ...
2
votes
0
answers
110
views
How can prevent dotnet core SignalR json serilizer from generate invalid json format
I create web-app with .net 5 and use SignalR for real-time communicate.
but when I send message to client with SendAsync() like this:
await _hubContext
.Clients
.Group(...
3
votes
0
answers
2k
views
Returning Large Object in .Net 5 Getting Error: The JSON value of length 204472564 is too large and not supported
I have a webservice that gets an SSRS report as a byte[] array and returns it as a class object with some other data (ids, sucess message etc...).
It works fine for any report under 100 MB. However ...
5
votes
1
answer
2k
views
Serialisation of custom type inheriting Dictionary using System.Text.Json does not serialise other properties
I have the following type:
public class Product : Dictionary<string, object>
{
[JsonInclude]
public string ProductId { get; set; }
public Product(string productId) : base()
{
...
2
votes
0
answers
353
views
Customise Json Serialisation of properties per class
The new System.Text.Json serialiser supports setting a naming policy as follows:
var options = new JsonSerializerOptions {
PropertyNamingPolicy = myPolicy
}
However these options are applied ...
1
vote
0
answers
247
views
Problem returning Results in JSON from Web App .Net Core 5
Good afternoon colleagues, I have the following problem. I am developing a project in ASP.NET Core MVC (.NET 5) And within it I have the call to an API, the APIs return the values in JSON without ...
0
votes
1
answer
2k
views
Can I create a report on the fly by passing a Json string?
I have designed a report using the Community Designer, and, during design I used a JSON string as my data source. I understand I can point a different datasource when instantiating my report during ...
2
votes
2
answers
3k
views
Azure Function with HTTP trigger fails to bind model from JSON payload (.NET 5 out-of-proc )
I am running an isolated process function that is failing to bind the input model from the JSON payload.
This is my function:
[Function("AddChip")]
public async Task<HttpResponseData> ...
1
vote
1
answer
52
views
Bind a complex type property to a primary type
Suppose I have a ViewModel in .net core client,
public class MyViewModel{
...
public List<MyClass> NamesList{get;set;}
...
}
where MyClass is defined as below,
public class MyClass{
...
1
vote
4
answers
5k
views
Custom error response for incorrect json. Dotnet Core Web API
Is there a mechanism for returning a custom error response if an invalid type is given to a WebApi in Dotnet Core?
E.G.
if I have a class that looks like this
public class SomeApiClass
{
public ...
1
vote
1
answer
215
views
Parse 24-char hex value in json string as BsonObjectId
I am trying to implement the following flow in a .NET5 Web API (rest endpoint).
Receive mongodb query as json string
Convert json string to BsonDocument
Use BsonDocument to query MongoDb collection
...
0
votes
1
answer
455
views
Throws an exception on a return while get another table data through foreign key in .NET 5 Web API
Doctor detail include into patient object in this method but it return a exception.
[HttpGet("{id}", Name = "GetPatient")]
public IActionResult Get(string id)
{
...
1
vote
1
answer
34
views
JSON Response Formatted Odd
I would appreciate help if possible with this. I've come to expect JSON payloads in a particular format and I do not yet know why it's not returning as such.
The payload is including fields for $id ...
2
votes
1
answer
1k
views
Change Blazor JS interop Serializer Settings
I am looking to see how to set the json serializor converter settings when you call _jsRuntime.InvokeAsync method. The method it self doesn't take in any json serialization settings. I believe you ...
2
votes
3
answers
3k
views
Asp.Net Core Keep default output formatter after adding custom
I'm using Net 5.0.
I added custom Output formatter for ObjectResult.
var result = new ObjectResult(list)
{
StatusCode = (int)HttpStatusCode.OK
};
result.Formatters.Add(new ExcelOutputFormatter());
...
0
votes
1
answer
387
views
How to deserialize JSON text on the fly in C#
I am reading/receiving blocks of bytes from an async function which I buffer in a MemoryStream and then deserialize to a C# object.
public async Task<Message> Read()
{
byte[] ...
1
vote
2
answers
2k
views
C# .NET5 Single File Application Read and Parse Json / Txt or other file formats from directory
I am reading files on .NET Framework like this:
string path = AppDomain.CurrentDomain.BaseDirectory + @"sources\settings.json";
string jsonResult = File.ReadAllText(path);
return JsonConvert....
5
votes
2
answers
4k
views
JsonConstructorAttribute in System.Text.Json (but not Newtonsoft.Json) results in exception when property and constructor argument types differ
Given a Base64 string, the following sample class will deserialize properly using Newtonsoft.Json, but not with System.Text.Json:
using System;
using System.Text.Json.Serialization;
public class ...
2
votes
1
answer
839
views
.NET 5 + Custom appsettings.json - The SPA default page middleware could not return the default page
I have a C# .NET5 Project with ReactJS (VS Project Template for C# projects).
If I do not change appsettings.json and launchSettings.json everything works fine (localhost DEV and also TEST server ...
4
votes
2
answers
9k
views
HttpRequestData wraps body in { "json" : "" }
I am trying to set up an .NET 5 Azure Http function that takes a request with a json body and outputs it to the logs.
using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker;
using ...
0
votes
1
answer
54
views
.Net5 backend receives empty JSON
I implemented a simple server with .Net5 and an Angular frontend. My api works with post man but only if I set Content-Type equal to application/x-www-form-urlencoded. When I use Content-Type equal to ...
1
vote
0
answers
126
views
.NET 5 WebApp can not load multiple configuration json files
I have these json configuration files:
appsettings.json -> common configuration
{
"AllowedHosts": "*"
}
and appsettingsAmbiente.json -> specific environment ...
1
vote
1
answer
1k
views
Dynamically create JSON object using JSON Path in C#
I have a list of key-value pair of json property path and its value,
Key: $.orderNumber Value: "100001"
Key: $.orderedOn ...
0
votes
1
answer
123
views
How to deserialize quoted nested object using System.Text.Json in .Net 5
I got this two classes
public class RootObj
{
public int a { get; set; }
public SubObj sub { get; set; }
}
public class SubObj
{
public int b { get; set; }
}
The JSON string to be ...
0
votes
1
answer
368
views
Parse JSON with indexes in property name to list
Dealing with a JSON response similar to this, some of these responses can be up to 500+ items.
{
"name1": "Paul",
"address1": "123 paul lane",
"...
5
votes
1
answer
3k
views
System.Text.Json.Serialization Does not appear to work for JSON with NESTED classes
How do I define a class that works using only System.Text.Json.Serialization?
Using Microsoft's new alternative to Newtonsoft deserialization does not currently work for nested classes, as all the ...
0
votes
1
answer
236
views
How would I create the data models for my JSON string in .NET Core 5.x
I am trying to follow along with this:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-5.0#make-post-put-and-delete-requests
This is my JSON string I need to ...
0
votes
2
answers
478
views
System.Text.Json.Deserialize can still not handle TimeSpan in .NET Core 5?
I have the following TimeSpan JSON string genereated from JsonSerilizer.Serialize<TimeSpan>(MyTymeSpan); :
jsonString= {"Ticks":1770400500000,"Days":2,"Hours":1,&...
0
votes
1
answer
778
views
How to deserialize nested timespan property with System.Text.Json?
I am trying to deserialize json data with System.Text.Json utilizing converters.
The raw content of the http response shows that the json contains valid data
The converter to deserialize the content ...
0
votes
1
answer
1k
views
Unable to Deserialize Json in WebApi with JsonSubTypes in .NET 5, although able to in Console App
I am trying to implement polymorphic deserialization in my project's web api. I have the following base and derived class.
Base class
[JsonConverter(typeof(JsonSubtypes), "PointType")]
...
3
votes
0
answers
1k
views
System.Text.Json - How to deserialize immutable objects with ReferenceHandler.Preserve?
I found out how to use System.Text.Json with immutable objects using the [JsonConstructor] attribute (see: How to use immutable types), and separately how to preserve references with .Net 5.
...
2
votes
1
answer
3k
views
.NET5 JsonPatchDocument.ApplyTo throws when add or replace
I got a problem with my JsonPatchDocument object, which can Remove value from the field, but cannot add/replace it.
My controller code is as following:
[HttpPatch]
[Route("{layersGroupId}")]
...
0
votes
3
answers
668
views
Deserialize json with data property to a list of objects to what is inside the json array
I try to deserealize it to return to javascript only the data property which is a list.
My controller class which returns the json to javascript:
public ActionResult<IEnumerable> GetCourseThemes(...
-2
votes
1
answer
155
views
(De)serializing child JSON attributes into class properties
Let's say I have a controller which accepts the following JSON:
{
"propA": "val1",
"propB": {
"propC": "val2",
"propD&...
34
votes
2
answers
10k
views
How to use default serialization in a custom System.Text.Json JsonConverter?
I am writing a custom System.Text.Json.JsonConverter<T> to upgrade an old data model to a new version. I have overridden Read() and implemented the necessary postprocessing. However, I don't ...
0
votes
1
answer
2k
views
how do i pass a datatable from a .net core 5.0 web api to an angular front end as json?
My old .net core 2 web api project used newtonsoft to serialise a datatable to json which I then passed back to a front end (angular) site as json ie using something along the lines of:
Create a ...
0
votes
0
answers
205
views
Custom JSON Generic Type Serialization not working
I am using the new .NET serialization classes from System.Text.Json to deserialize a JSON response from a restful endpoint. The structure of the response is:
public class RemoteCallResultDto
{
...
1
vote
2
answers
2k
views
.NET 5 System.Text.Json configure [FromBody] to avoid deserialisation error with non-string dictionary key
I'm migrating a project from Microsoft.AspNetCore.Mvc.NewtonsoftJson to System.Text.Json. I couldn't do this in .NET Core 3.1 due to dotnet/runtime#38056 as some of my models contain properties of ...