Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You attempted to access the Error property for a successful result. A successful result has no Error. #500

Open
namigmustafa opened this issue Apr 8, 2023 · 8 comments

Comments

@namigmustafa
Copy link

namigmustafa commented Apr 8, 2023

I have receiving You attempted to access the Error property for a successful result. A successful result has no Error. error when I send value from service to controller. I receive it on service level.

public async Task<CSharpFunctionalExtensions.Result<QuestionDto>> GetQuestionWithElementsById2(int id)
    {
        var questionWithElements = await _tenantUnitOfWork.QuestionRepository.GetQuestionWithElementsById(id);

        var questionsWithElementsDto = _mapper.Map<QuestionDto>(questionWithElements);

        return Result.Success<QuestionDto>(questionsWithElementsDto);
    }

image

@titouancreach
Copy link

Is this a real error or just your debugger ? because I have the same in vs code when I inspect the value with the debugger, because it tries to show me the value of the Error even if there is no error.

@namigmustafa
Copy link
Author

It is real

@hankovich
Copy link
Collaborator

Show the stacktrace, please

@namigmustafa
Copy link
Author

namigmustafa commented Apr 14, 2023

 at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCoreAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.JsonSerializer.WriteCore[TValue](Utf8JsonWriter writer, TValue& value, JsonTypeInfo jsonTypeInfo, WriteStack& state)
   at System.Text.Json.JsonSerializer.<WriteStreamAsync>d__121`1.MoveNext()
   at System.Text.Json.JsonSerializer.<WriteStreamAsync>d__121`1.MoveNext()
   at System.Text.Json.JsonSerializer.<WriteStreamAsync>d__121`1.MoveNext()
   at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.<WriteResponseBodyAsync>d__5.MoveNext()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<<InvokeNextResultFilterAsync>g__Awaited|30_0>d`2.MoveNext()
   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>d.MoveNext()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<<InvokeAsync>g__Awaited|17_0>d.MoveNext()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<<InvokeAsync>g__Awaited|17_0>d.MoveNext()
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<<Invoke>g__AwaitRequestTask|6_0>d.MoveNext()
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.<Invoke>d__6.MoveNext()
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<<Invoke>g__Awaited|6_0>d.MoveNext()

@hankovich
Copy link
Collaborator

hankovich commented Apr 14, 2023

The stacktrace shows that this error was thrown during response formatting, i.e. result was returned not only from service to controller, but also it was returned from controller itself.

If you want to return results from controller, you may use this extension to add corresponding converters for System.Text.Json.

@namigmustafa
Copy link
Author

Is that link should have something? it is empty page? :)

@hankovich
Copy link
Collaborator

My bad, updated it 👍

@namigmustafa
Copy link
Author

huge thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants