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

The method is returning object as Result<Result<dynamic>> instead of Result<dynamic> since version 3.7 #144

Open
kuldeepGDI opened this issue Aug 10, 2022 · 5 comments

Comments

@kuldeepGDI
Copy link

kuldeepGDI commented Aug 10, 2022

Hi,

since the update of fluentResults to 3.7 we are facing following issue. We have a code which functions as following

public static Result<dynamic> DynamicConvert(dynamic source, Type dest)
        {
            var result = new Result<dynamic>();
            try
            {
                var converted = Convert.ChangeType(source, dest);
                return result.WithValue(converted);
            }
            catch (Exception e)
            {
                return Result.Fail($"{e.Message}");
            }
        }

this was working fine until 3.6. After updating to 3.7 we notice that now result.WithValue is returning Result of Result object however earlier (version 3.6) it was returning simple Result object, As an example on version 3.7+ we now get

Result<Result<string>> 

however on prior versions 3.6 and below we get

Result<string> 

in both above cases

  1. Type is typeof(string)
  2. source is "SomeStringValue"

ON debugging i found that somehow with 3.7 now there is an extra call occurring to following method in Results.cs file

public static Result<TValue> Ok<TValue>(TValue value)
        {
            var result = new Result<TValue>();
            result.WithValue(value);
            return result;
        }

And this is leading to an extra wrapping of Result object

Any hints?

@kuldeepGDI kuldeepGDI changed the title The Dictionary<string, object> is returning object as Result<string[]> instead of string[] since 3.7 The Dictionary<string, object> is returning object as Result<Result<dynamic>> instead of Result<dynamic> since 3.7 Aug 10, 2022
@kuldeepGDI kuldeepGDI changed the title The Dictionary<string, object> is returning object as Result<Result<dynamic>> instead of Result<dynamic> since 3.7 The method is returning object as Result<Result<dynamic>> instead of Result<dynamic> since version 3.7 Aug 10, 2022
@altmann
Copy link
Owner

altmann commented Aug 11, 2022

Hi,

in the release notes I see that we added a new implicit conversation in v3.7 (see https://github.com/altmann/FluentResults/releases/tag/v3.7) Issue and PR is also linked.

image

I think that the method WithValue() works correctly. But after WithValue() an implicit conversation occur and the Result is wrapped in another Result object but I don't really know why.

The git repo of FluentResult is really easy to setup locally on a dev machine. Only cloning and building. If you need a solution asap it would be great if you can create a test to reproduce this issue and maybe you find the solution. Maybe we have to check in the implicit conversation if the TValue is already a Result and then we can return it and don't wrap it again.

@kuldeepGDI
Copy link
Author

I did create a test locally in fluent results repo, i can push the branch if you would like ? However, i am not sure if i have the time to fix the bug currently, although would be nice to have the solution asap. I will try to fix it once i have some free time myself, but would be great if some one can really look into it until then. Thanks a lot

@altmann
Copy link
Owner

altmann commented Aug 11, 2022

@kuldeepGDI I invested some time and have now a working solution. I don't have much experience with dynamic in c# because I try to prevent it in all my projects.

Please look at the pr #145. There you see the changes and also the test which I added. Please let me know your opinion.

@kuldeepGDI
Copy link
Author

I added my comment there, when would be the new version published then ? THanks a lot for quick fix !

@altmann
Copy link
Owner

altmann commented Aug 12, 2022

The new version 3.11 is released in some minutes. I keep the issue open. If you know why its double casted please let me know.

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

2 participants