C
C#5mo 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
SylveonDekoOP5mo 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
SylveonDekoOP5mo ago
:foxexited:
HtmlCompiler
HtmlCompiler5mo ago
what a beefy json maybe the error is in the sender, not in the receiver
SylveonDeko
SylveonDekoOP5mo 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
SylveonDekoOP5mo ago
No description
HtmlCompiler
HtmlCompiler5mo 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
SylveonDekoOP5mo ago
At the controller class I’ve tried with valid json too
HtmlCompiler
HtmlCompiler5mo ago
what do you mean, you've put this in parameter in the routing attribute of the class itself?
SylveonDeko
SylveonDekoOP5mo ago
Correct Also I solved this, at least for afk, somehow removing the required attribute fixed it
HtmlCompiler
HtmlCompiler5mo 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
SylveonDekoOP5mo 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
Angius5mo ago
How are you sending that data? Does it work when sending with Swagger or some API client like Bruno or Insomnium?
SylveonDeko
SylveonDekoOP5mo 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
Angius5mo ago
Try wrapping the parameter into a record or something?
SylveonDeko
SylveonDekoOP5mo ago
Tried that, then it says it requires that, even if I provide the correct json for it
Angius
Angius5mo ago
What do the logs and the debugger say? Is it this action that get's hit?
SylveonDeko
SylveonDekoOP5mo ago
It is yeah, it returns a 400, the body gets received
HtmlCompiler
HtmlCompiler5mo ago
have you tried just deserializing the model calling stj deserialize directly?
SylveonDeko
SylveonDekoOP5mo 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
Kouhai5mo ago
What's the content-type of the request?
SylveonDeko
SylveonDekoOP5mo 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
Kouhai5mo ago
Hmmm, are they both in the same controller?
SylveonDeko
SylveonDekoOP5mo ago
yep
Kouhai
Kouhai5mo ago
:ThinkingRot:
SylveonDeko
SylveonDekoOP5mo ago
$$paste $paste
MODiX
MODiX5mo 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
SylveonDekoOP5mo ago
BlazeBin - ackfvzwsxxkp
A tool for sharing your source code with the world!
SylveonDeko
SylveonDekoOP5mo ago
i am incredibly confused
Kouhai
Kouhai5mo ago
So not even "{"commandName": "test"}" work?
SylveonDeko
SylveonDekoOP5mo ago
correct
Kouhai
Kouhai5mo ago
:huh:
SylveonDeko
SylveonDekoOP5mo ago
No description
SylveonDeko
SylveonDekoOP5mo ago
No description
SylveonDeko
SylveonDekoOP5mo ago
now heres something funny and its what drove me the most insane
SylveonDeko
SylveonDekoOP5mo ago
No description
SylveonDeko
SylveonDekoOP5mo 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
Kouhai5mo ago
Hmmm, actually {"commandName": "test"} should not work, because {"commandName": "test"} means there should be a model to bind to
SylveonDeko
SylveonDekoOP5mo ago
yeah, this should work but now look at my post method from here
SylveonDeko
SylveonDekoOP5mo ago
No description
Kouhai
Kouhai5mo ago
:ASthink:
SylveonDeko
SylveonDekoOP5mo ago
its like its gaslighting me
Kouhai
Kouhai5mo 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
SylveonDekoOP5mo 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
Kouhai5mo ago
:megaweird:
SylveonDeko
SylveonDekoOP5mo ago
$paste
MODiX
MODiX5mo 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
SylveonDekoOP5mo 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
SylveonDekoOP5mo ago
GitHub
Mewdeko/src/Mewdeko/Program.cs at psqldeko · SylveonDeko/Mewdeko
Mewdeko. Contribute to SylveonDeko/Mewdeko development by creating an account on GitHub.
Kouhai
Kouhai5mo ago
LGTM, nothing there should cause any problems
SylveonDeko
SylveonDekoOP5mo ago
right but there are problems and its driving me up the damn wall
Kouhai
Kouhai5mo ago
Does the serialization error also happen when sending "test" from postman?
SylveonDeko
SylveonDekoOP5mo ago
yes
Kouhai
Kouhai5mo ago
Okay what happens if you remove commandName entirely
SylveonDeko
SylveonDekoOP5mo ago
e well then it goes through, if i make it part of the route it goes through
Kouhai
Kouhai5mo ago
I know it's a weird question, is your keyboard langauge "EN"?
SylveonDeko
SylveonDekoOP5mo ago
im on net8 btw, lang ver 12 yes
Kouhai
Kouhai5mo ago
Okay, can you try making a request using cURL?
SylveonDeko
SylveonDekoOP5mo ago
sure same error lel
SylveonDeko
SylveonDekoOP5mo ago
No description
SylveonDeko
SylveonDekoOP5mo 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
SylveonDekoOP5mo ago
No description
SylveonDeko
SylveonDekoOP5mo ago
i only uncommented it because the delete request wasnt working :Bruh:
Kouhai
Kouhai5mo ago
Hmmm Can you try escaping " in the body? (for curl)
SylveonDeko
SylveonDekoOP5mo ago
no no, that is the expected output what it did just now
Kouhai
Kouhai5mo ago
Ik
SylveonDeko
SylveonDekoOP5mo ago
something here is causing the json to get lost
Kouhai
Kouhai5mo ago
But it's still not working for the DELETE endpoint right 😅 ?
SylveonDeko
SylveonDekoOP5mo ago
sec
Kouhai
Kouhai5mo ago
Also I think the body is only allowed to be read once
SylveonDeko
SylveonDekoOP5mo ago
yeah thats what i was thinking it works now :Bruh: i am so god damn confused right now
Kouhai
Kouhai5mo ago
Wait Even with the logger?
SylveonDeko
SylveonDekoOP5mo ago
no the logger is disabled
Kouhai
Kouhai5mo ago
Yeah Makes sense
SylveonDeko
SylveonDekoOP5mo ago
but heres the thing i only enabled the logger because i was getting a 403 no sorry 400
Kouhai
Kouhai5mo ago
:huh: In the DELETE endpoint?
SylveonDeko
SylveonDekoOP5mo ago
anyway, it works now yeah
Kouhai
Kouhai5mo ago
If it works it works :Shruge:
SylveonDeko
SylveonDekoOP5mo ago
yeah lmao
HtmlCompiler
HtmlCompiler5mo 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