I believe this is what you’re looking for. The jist is, the compiler needs to verify statically that you’re returning something from every code path. Because you’re using this extension method, it’s not able to deduce the fact, and you’re getting the error:
CS0161 ‘Foo()’: not all code paths return a value
solved Extension method to throw new Exception