vkhorikov / CSharpFunctionalExtensions

Functional extensions for C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

namigmustafa opened this issue · comments

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

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.

It is real

Show the stacktrace, please

 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()

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.

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

My bad, updated it 👍

huge thanks