Closed selaromdotnet closed 3 months ago
edit: previously thought it might be the latest vs that broke it, but tried again with older version and got the same error. Funnily enough, CriticalError also works, in that I get a Result back of that type. Error, however, always returns null!
I just added this package to my project. In my first tests, I got a null error when I wanted to return the Error class. There are no problems with other return types. However, when returning with Error, a null result is returned to the person calling the method.
I can confirm this.
When i return Result.Error
or Result.CriticalError
from a method and then i to .ToMinimalApiResult
i get a NullReferenceException
. and the API breaks.
Trying to debug the issue, the result input parameter is null:
But the problem is not only in .ToMinimalApiResult
, is the whole Result.Error problematic. If return a Result.Error from a method and try to access it i get a nullrefrenceException no matter what
EDIT: downgrading to 8.0 fixes the problem.
[celebrate] Josh Morales reacted to your message:
From: Steve Smith @.> Sent: Saturday, May 25, 2024 5:17:38 PM To: ardalis/Result @.> Cc: Josh Morales @.>; Author @.> Subject: Re: [ardalis/Result] Result.Error returns null instead of Result when returned from a method called from a controller (Issue #186)
Closed #186https://github.com/ardalis/Result/issues/186 as completed via #189https://github.com/ardalis/Result/pull/189.
— Reply to this email directly, view it on GitHubhttps://github.com/ardalis/Result/issues/186#event-12933563119, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAEKKBXSJCMKCX55YZFZ3V3ZEDBTFAVCNFSM6AAAAABIED6DM6VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJSHEZTGNJWGMYTCOI. You are receiving this because you authored the thread.Message ID: @.***>
I'm having the weirdest issue, and I'm sure I'm probably just setting this up or using it wrong, but I can't figure out what that is.
I created a controller that I want to use to call a service that returns a result. If the result is successful, I get that result just fine. However if the service fails for whatever reason, and I attempt to return an error, that error result is null instead.
I created a super simple solution that mimics what I'm doing and does demonstrate the described behavior here: https://1drv.ms/u/s!Ahj4lgIVz2Ld6qwyH38Csz1FKpGY0g?e=p9Ac2D
It's just a controller with an injected service that returns one of the two results. The Success result works, but the Error result throws a null reference exception back in the calling controller because null is returned instead.
What am I doing wrong? this weirdly seems to work in other spots using razor pages, so I think maybe there's something wrong with my controller context or setup?
Any ideas? Much appreciated!!