C
C#4mo ago
SylveonDeko

Im getting a very ambiguous error when trying to get data via aspnet

the error;
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"model": [
"The model field is required."
]
},
"traceId": "00-553b2b7da84c52f6ab86d008eb76943f-adb629679e4bd9de-00"
}
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"model": [
"The model field is required."
]
},
"traceId": "00-553b2b7da84c52f6ab86d008eb76943f-adb629679e4bd9de-00"
}
The code:
/// <summary>
/// Updates a guild config from the provided json and guildid
/// </summary>
/// <param name="guildId">The guildid to update a config for</param>
/// <param name="model">The json body of the model to update</param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> UpdateGuildConfig(ulong guildId, [FromBody] GuildConfig model)
{
try
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
await service.UpdateGuildConfig(guildId, model);
return Ok();
}
catch (Exception e)
{
Log.Error(e, "Error updating guild config");
return StatusCode(500);
}
}
}
/// <summary>
/// Updates a guild config from the provided json and guildid
/// </summary>
/// <param name="guildId">The guildid to update a config for</param>
/// <param name="model">The json body of the model to update</param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> UpdateGuildConfig(ulong guildId, [FromBody] GuildConfig model)
{
try
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
await service.UpdateGuildConfig(guildId, model);
return Ok();
}
catch (Exception e)
{
Log.Error(e, "Error updating guild config");
return StatusCode(500);
}
}
}
79 Replies
SylveonDeko
SylveonDekoOP4mo ago
The json im sending as the body https://paste.mod.gg/dnngsmodvzpw/0
BlazeBin - dnngsmodvzpw
A tool for sharing your source code with the world!
SylveonDeko
SylveonDekoOP4mo ago
:foxexited:
Omnissiah
Omnissiah4mo ago
what a beefy json maybe the error is in the sender, not in the receiver
SylveonDeko
SylveonDekoOP4mo ago
which is what im trying to find out im actually gonnago insane
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"message": [
"The message field is required."
]
},
"traceId": "00-f5d127fc6a00e0cd28fe148c883461a5-aba989072b5d28e9-00"
}
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"message": [
"The message field is required."
]
},
"traceId": "00-f5d127fc6a00e0cd28fe148c883461a5-aba989072b5d28e9-00"
}
SylveonDeko
SylveonDekoOP4mo ago
No description
Omnissiah
Omnissiah4mo ago
well, that's fair, it's not valid json also, where is guildId configured
[HttpPost] public async Task<IActionResult> UpdateGuildConfig(ulong guildId, [FromBody] GuildConfig model)
like, the route
SylveonDeko
SylveonDekoOP4mo ago
At the controller class I’ve tried with valid json too
Omnissiah
Omnissiah4mo ago
what do you mean, you've put this in parameter in the routing attribute of the class itself?
SylveonDeko
SylveonDekoOP4mo ago
Correct Also I solved this, at least for afk, somehow removing the required attribute fixed it
Omnissiah
Omnissiah4mo ago
yes, removing required "fixes" it but uhm i was sure i wrote another message what is happening was it another thread? i remember saying that some tests could be useful
SylveonDeko
SylveonDekoOP4mo ago
this issue has reappeared but this time it doesnt even make sense the response i send:
"test"
"test"
The controller code:
/// <summary>
/// Remove a dpo
/// </summary>
/// <param name="guildId"></param>
/// <param name="commandName"></param>
/// <returns></returns>
[HttpDelete("dpo/{guildId}")]
public async Task<IActionResult> RemoveDpo(ulong guildId, [FromBody] string commandName)
{
var com = cmdServ.Search(commandName);
if (!com.IsSuccess)
return BadRequest(com);
await dpoService.RemoveOverride(guildId, commandName);
return Ok();
}
/// <summary>
/// Remove a dpo
/// </summary>
/// <param name="guildId"></param>
/// <param name="commandName"></param>
/// <returns></returns>
[HttpDelete("dpo/{guildId}")]
public async Task<IActionResult> RemoveDpo(ulong guildId, [FromBody] string commandName)
{
var com = cmdServ.Search(commandName);
if (!com.IsSuccess)
return BadRequest(com);
await dpoService.RemoveOverride(guildId, commandName);
return Ok();
}
The response:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"commandName": [
"The commandName field is required."
]
},
"traceId": "00-b90dcda822a05ec97c546c28d360e4ec-3cd9035000a26306-00"
}
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"commandName": [
"The commandName field is required."
]
},
"traceId": "00-b90dcda822a05ec97c546c28d360e4ec-3cd9035000a26306-00"
}
I am actually going to go insane and yes, i have tried doing {"commandName": "test"} too
Angius
Angius4mo ago
How are you sending that data? Does it work when sending with Swagger or some API client like Bruno or Insomnium?
SylveonDeko
SylveonDekoOP4mo ago
Tried with postman and swagger, no go That’s why im stumped, I would expect at least swagger to be able to do it
Angius
Angius4mo ago
Try wrapping the parameter into a record or something?
SylveonDeko
SylveonDekoOP4mo ago
Tried that, then it says it requires that, even if I provide the correct json for it
Angius
Angius4mo ago
What do the logs and the debugger say? Is it this action that get's hit?
SylveonDeko
SylveonDekoOP4mo ago
It is yeah, it returns a 400, the body gets received
Omnissiah
Omnissiah4mo ago
have you tried just deserializing the model calling stj deserialize directly?
SylveonDeko
SylveonDekoOP4mo ago
Model or just a string it does the same thing, it doesn’t get to the content of the controller at all
[13:53:42 INF] | #Mewdeko | Request received: DELETE /botapi/Permissions/dpo/900378009188565022
[13:53:42 INF] | #Mewdeko | Request body: "help"
[13:53:42 INF] | #Mewdeko | Executing endpoint 'Mewdeko.Controllers.PermissionsController.RemoveDpo (Mewdeko)'
[13:53:42 INF] | #Mewdeko | Route matched with {action = "RemoveDpo", controller = "Permissions"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] RemoveDpo(UInt64, System.String) on controller Mewdeko.Controllers.PermissionsController (Mewdeko).
[13:53:42 INF] | #Mewdeko | Executing BadRequestObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ValidationProblemDetails'.
[13:53:42 INF] | #Mewdeko | Executed action Mewdeko.Controllers.PermissionsController.RemoveDpo (Mewdeko) in 87.1177ms
[13:53:42 INF] | #Mewdeko | Executed endpoint 'Mewdeko.Controllers.PermissionsController.RemoveDpo (Mewdeko)'
[13:53:42 INF] | #Mewdeko | Request finished HTTP/1.1 DELETE http://localhost:5001/botapi/Permissions/dpo/900378009188565022 - 400 null application/problem+json; charset=utf-8 130.7832ms
[13:53:42 INF] | #Mewdeko | Request received: DELETE /botapi/Permissions/dpo/900378009188565022
[13:53:42 INF] | #Mewdeko | Request body: "help"
[13:53:42 INF] | #Mewdeko | Executing endpoint 'Mewdeko.Controllers.PermissionsController.RemoveDpo (Mewdeko)'
[13:53:42 INF] | #Mewdeko | Route matched with {action = "RemoveDpo", controller = "Permissions"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] RemoveDpo(UInt64, System.String) on controller Mewdeko.Controllers.PermissionsController (Mewdeko).
[13:53:42 INF] | #Mewdeko | Executing BadRequestObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ValidationProblemDetails'.
[13:53:42 INF] | #Mewdeko | Executed action Mewdeko.Controllers.PermissionsController.RemoveDpo (Mewdeko) in 87.1177ms
[13:53:42 INF] | #Mewdeko | Executed endpoint 'Mewdeko.Controllers.PermissionsController.RemoveDpo (Mewdeko)'
[13:53:42 INF] | #Mewdeko | Request finished HTTP/1.1 DELETE http://localhost:5001/botapi/Permissions/dpo/900378009188565022 - 400 null application/problem+json; charset=utf-8 130.7832ms
heres what logs say, route gets matched just fine i added te request received and body to the logs
Kouhai
Kouhai4mo ago
What's the content-type of the request?
SylveonDeko
SylveonDekoOP4mo ago
application/json now the funny thing is, i have a post request structured in the exact same way it works fine this delete request doesnt
Kouhai
Kouhai4mo ago
Hmmm, are they both in the same controller?
SylveonDeko
SylveonDekoOP4mo ago
yep
Kouhai
Kouhai4mo ago
:ThinkingRot:
SylveonDeko
SylveonDekoOP4mo ago
$$paste $paste
MODiX
MODiX4mo ago
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
SylveonDeko
SylveonDekoOP4mo ago
BlazeBin - ackfvzwsxxkp
A tool for sharing your source code with the world!
SylveonDeko
SylveonDekoOP4mo ago
i am incredibly confused
Kouhai
Kouhai4mo ago
So not even "{"commandName": "test"}" work?
SylveonDeko
SylveonDekoOP4mo ago
correct
Kouhai
Kouhai4mo ago
:huh:
SylveonDeko
SylveonDekoOP4mo ago
No description
SylveonDeko
SylveonDekoOP4mo ago
No description
SylveonDeko
SylveonDekoOP4mo ago
now heres something funny and its what drove me the most insane
SylveonDeko
SylveonDekoOP4mo ago
No description
SylveonDeko
SylveonDekoOP4mo ago
doing this works, but i dont want this to be the solution
[HttpDelete("dpo/{guildId}/{commandName}")]
public async Task<IActionResult> RemoveDpo(ulong guildId, string commandName)
[HttpDelete("dpo/{guildId}/{commandName}")]
public async Task<IActionResult> RemoveDpo(ulong guildId, string commandName)
im about ready to go to a mental institution this post method was working yesterday i have changed nothing
Kouhai
Kouhai4mo ago
Hmmm, actually {"commandName": "test"} should not work, because {"commandName": "test"} means there should be a model to bind to
SylveonDeko
SylveonDekoOP4mo ago
yeah, this should work but now look at my post method from here
SylveonDeko
SylveonDekoOP4mo ago
No description
Kouhai
Kouhai4mo ago
:ASthink:
SylveonDeko
SylveonDekoOP4mo ago
its like its gaslighting me
Kouhai
Kouhai4mo ago
I mean...it's working on my end :Kek:
[ApiController]
[Route("botapi/[controller]")]
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}


[HttpDelete("dpo/{guildId}")]
public IActionResult RemoveDpo(ulong guildId, [FromBody] string commandName)
{
return Ok(commandName + "_test");
}
}
[ApiController]
[Route("botapi/[controller]")]
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}


[HttpDelete("dpo/{guildId}")]
public IActionResult RemoveDpo(ulong guildId, [FromBody] string commandName)
{
return Ok(commandName + "_test");
}
}
No description
SylveonDeko
SylveonDekoOP4mo ago
i swear to god if this is some weird linux shit same thing happens on my linux server the entire api is doing it now 💀 i am extremely confused
Kouhai
Kouhai4mo ago
:megaweird:
SylveonDeko
SylveonDekoOP4mo ago
$paste
MODiX
MODiX4mo ago
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
SylveonDeko
SylveonDekoOP4mo ago
see if theres something wrong weith my program.cs https://paste.mod.gg/smdhaqrxnmct/1
BlazeBin - smdhaqrxnmct
A tool for sharing your source code with the world!
SylveonDeko
SylveonDekoOP4mo ago
GitHub
Mewdeko/src/Mewdeko/Program.cs at psqldeko · SylveonDeko/Mewdeko
Mewdeko. Contribute to SylveonDeko/Mewdeko development by creating an account on GitHub.
Kouhai
Kouhai4mo ago
LGTM, nothing there should cause any problems
SylveonDeko
SylveonDekoOP4mo ago
right but there are problems and its driving me up the damn wall
Kouhai
Kouhai4mo ago
Does the serialization error also happen when sending "test" from postman?
SylveonDeko
SylveonDekoOP4mo ago
yes
Kouhai
Kouhai4mo ago
Okay what happens if you remove commandName entirely
SylveonDeko
SylveonDekoOP4mo ago
e well then it goes through, if i make it part of the route it goes through
Kouhai
Kouhai4mo ago
I know it's a weird question, is your keyboard langauge "EN"?
SylveonDeko
SylveonDekoOP4mo ago
im on net8 btw, lang ver 12 yes
Kouhai
Kouhai4mo ago
Okay, can you try making a request using cURL?
SylveonDeko
SylveonDekoOP4mo ago
sure same error lel
SylveonDeko
SylveonDekoOP4mo ago
No description
SylveonDeko
SylveonDekoOP4mo ago
.... so on a hunch i commented out my request logger which i added for debugging and the post request goes through // app.Use(async (context, next) => // { // var logger = context.RequestServices.GetRequiredService<ILogger<Mewdeko>>(); // logger.LogInformation($"Request received: {context.Request.Method} {context.Request.Path}"); // logger.LogInformation($"Request body: {await new StreamReader(context.Request.Body).ReadToEndAsync()}"); // await next(); // });
SylveonDeko
SylveonDekoOP4mo ago
No description
SylveonDeko
SylveonDekoOP4mo ago
i only uncommented it because the delete request wasnt working :Bruh:
Kouhai
Kouhai4mo ago
Hmmm Can you try escaping " in the body? (for curl)
SylveonDeko
SylveonDekoOP4mo ago
no no, that is the expected output what it did just now
Kouhai
Kouhai4mo ago
Ik
SylveonDeko
SylveonDekoOP4mo ago
something here is causing the json to get lost
Kouhai
Kouhai4mo ago
But it's still not working for the DELETE endpoint right 😅 ?
SylveonDeko
SylveonDekoOP4mo ago
sec
Kouhai
Kouhai4mo ago
Also I think the body is only allowed to be read once
SylveonDeko
SylveonDekoOP4mo ago
yeah thats what i was thinking it works now :Bruh: i am so god damn confused right now
Kouhai
Kouhai4mo ago
Wait Even with the logger?
SylveonDeko
SylveonDekoOP4mo ago
no the logger is disabled
Kouhai
Kouhai4mo ago
Yeah Makes sense
SylveonDeko
SylveonDekoOP4mo ago
but heres the thing i only enabled the logger because i was getting a 403 no sorry 400
Kouhai
Kouhai4mo ago
:huh: In the DELETE endpoint?
SylveonDeko
SylveonDekoOP4mo ago
anyway, it works now yeah
Kouhai
Kouhai4mo ago
If it works it works :Shruge:
SylveonDeko
SylveonDekoOP4mo ago
yeah lmao
Omnissiah
Omnissiah4mo ago
noo-ooo the controller maybe is not the issue analyze this thing giving the string to STJ.Deserialize<>
Want results from more Discord servers?
Add your server