Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

462
Visualizações
ExecuteAsync() causing hard crash with no exception

Here's the question: What would be stopping this code from executing this http request?

Here's the setup: I am doing a project that has multiple API's, and this is one method that is called within the first to the second for validation info. The method, in theory should make the request, send the model to the second service, and return back with something that is returned at the end of this method.

When running both API's locally with breakpoints to see if they are being hit, the second never gets hit, because the moment the ExecuteAsync() line is hit, it hard crashes, then restarts the first API. I dont think I did anything wrong here, but there isn't any sort of stack trace or exception that it throws at me, even if I put it into a try/catch. Is this a known issue or am I just doing something wrong here?

        public async Task<SharkTankValidationResponseModel> CheckIfValidRequest(SharkTankValidationModel requestModel)
        {
            // Setup rest client
            RestClient userRestClient = new RestClient(endpoint + "SharkTank/Validate");
            RestRequest userRequest = new RestRequest(Method.POST);
            // New request object for body

            userRequest.AddJsonBody(requestModel);
            // HTTP Request
            IRestResponse response = await userRestClient.ExecuteAsync(userRequest);
            return JsonConvert.DeserializeObject<SharkTankValidationResponseModel>(response.Content);
        }

On the top level, this is is how it is called. The model is being made correctly without issue, and I can step through the code all the way up to the execute function before it just hard crashes

                SharkTankValidationModel model = await makeSharkTankValidationModel(Method.GET, SharkTankConstants.GET_ALL_CLIENT_CATEGORY, null);
                SharkTankValidationResponseModel validationModel = await sharkTank.CheckIfValidRequest(model);

Gif for reference of steps running through debugger and the sudden crash https://imgur.com/bWSR78h

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Alright, figured it out after finally trying it in a way that let me see an exception in a response. The error was the following:

ActualMessage: "A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles."
BytePositionInLine: null
ClassName: "System.Text.Json.JsonException"
Data: null
ExceptionMethod: null
HResult: -2146233088
HelpURL: null
InnerException: null
LineNumber: null
Message: "A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles."
Path: "$.requestorRoles.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.AuthenticationType"
RemoteStackIndex: 0
RemoteStackTraceString: null
Source: "System.Text.Json"
StackTraceString: "   at System.Text.Json.ThrowHelper.ThrowJsonExcep
WatsonBuckets: null

Now the object I was using for a model was using microsoft's default claims object types for passing forward the claims. This apparently made the json serializer freak out and loop through itself over and over, and just hard crash when it found a loop.

The fix was just making a custom object type to map those claims to, and literally there were no issues using any of the 3 different HTTP method call types. Long story short, dont use the default claims type for things. Just makes issues.

over 4 years ago · Santiago Trujillo Relatório

0

Based on RestClient's documentation, ExecuteAsync does not throw an exception, but instead populates response.ErrorException and response.ErrorMessage if response.IsSuccessful is false. If you don't need access to the response StatusCode and only care about the body, just use PostAsync<T> instead.

public async Task<SharkTankValidationResponseModel> CheckIfValidRequest(SharkTankValidationModel requestModel)
{
    // Setup rest client
    RestClient userRestClient = new RestClient(endpoint);
    RestRequest userRequest = new RestRequest("SharkTank/Validate")
        .AddJsonBody(requestModel);
    // HTTP Request
    IRestResponse response = await userRestClient.PostAsync<SharkTankValidationResponseModel>(userRequest);
    return response;
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda