Result.Success(IEnumerable<T>) returns an empty set ??? Possibly in a Task??
I haven't had a chance to try to figure this one out. But I'm reporting it so its logged.
I had a method with a signature like this:
public async Task<Result<IEnumerable<MyObject>>> GetSomeObjects()
{
var myObjects = //Do something to get an IEnumerable<MyObject>
//At this point before the return, myObjects is definitely a sequence of Objects before the return.
//It is NOT an empty sequence.
return Result.Success(myObjects);
}
I was calling the method like this:
var r = await GetSomeObjects()
var objects = r.Value;
//here "objects" is an empty sequence. I'm completely baffled. The sequence changed to empty when being returned.
So I changed the method to this:
public async Task<Result<MyObject[]>> GetSomeObjects()
{
var myObjects = //Do something to get an IEnumerable<MyObject>
//All I've changed here is to Create an Array from the sequence and return it.
return Result.Success(myObjects.ToArray());
}
In calling function, objects is now an array with the objects in it (not empty)
I have no idea why that fixed the problem. Completely baffled. Is there a known issue of why IEnumerable might break when passed in a Result?
EDITS: 11:04am. Corrected some code mistakes and improved clarity.
Could you please post this issue in form of a failing test?
I will certainly try if I can manage to find time. But I have been working 12 hour days for weeks -- so many irons in the fire. This issue with IEnumerable came up during a live API testing scenario where I had another tech on the end of the line. I had to just get the code working and move on with all the other stuff I've got. I at least thought I should post about it so that it was noted in case anyone else has experienced an issue with IEnumerable or if there is something known already.
@pha3z I wasn't able to reproduce this issue on my own (tried a couple of options with the code you posted). Let me know if you could come up with a test (a raw code sample from your project would work too).
There's no known issue that would result in such behavior with IEnumerables.