Olá, estou recebendo uma mensagem de erro, tanto no swagger quanto no postman após Executar um novo cadastro no banco.
PS: Os dados são gravados normalmente no banco, mesmo assim recebo um status code "500". Fiz até um outro projeto em paralelo com o do curso, mesmo assim recebo o mesmo erro.
Mensagem de erro {Swagger}:
System.InvalidOperationException: No route matches the supplied values.
at Microsoft.AspNetCore.Mvc.CreatedAtActionResult.OnFormatting(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor.ExecuteAsyncCore(ActionContext context, ObjectResult result, Type objectType, Object value)
at Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor.ExecuteAsync(ActionContext context, ObjectResult result)
at Microsoft.AspNetCore.Mvc.ObjectResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
HEADERS
=======
Accept: */*
Host: localhost:7166
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0
:method: POST
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.5
Content-Type: application/json
Origin: https://localhost:7166
Referer: https://localhost:7166/swagger/index.html
TE: trailers
Content-Length: 258
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
Além disso, tentei reescrever o método AdicionarFilme/AdicionarPessoa, ambos os projetos, continuou funcionando normalmente, e com a mesma mensagem de erro...
Método antigo:
[HttpPost]
public IActionResult AdicionarPessoa([FromBody] Pessoa pessoa)
{
pessoa.SetPessoaId();
_context.Pessoas.Add(pessoa);
_context.SaveChanges();
return CreatedAtAction(nameof(RecuperaPessoaCadastrada),
new { id = pessoa.PessoaId },
pessoa);
}
Método reescrito:
[HttpPost]
public IActionResult AdicionarPessoa([FromBody] Pessoa pessoa)
{
pessoa.SetPessoaId();
_context.Pessoas.Add(pessoa);
_context.SaveChanges();
return RecuperaPessoaCadastrada(pessoa.PessoaId);
}
embora esteja funcionando, acredito que não deveria receber a mensagem de erro acima quando eu faço o /Post
.