It works as intended, finally it starts when an error occurs or when you get to a block, if they never list to the end, you will never reach the end of this block, so finally it should not be done.
The output creates a class to represent your method as a method + member state + place to resume, so each time you “resume” the method, you will never reach the final place if your finally be placed at the end of the enumeration, and you will never list to end. If you want the finally block to be executed each time, you will need to do a reliable evaluation, but you cannot say something like "I want it to be streamed, and finally called at the end, but the compiler automatically detects in the client code, if it never reaches Stream to the end, then finally call. " There is no “right” time for the final call, because all that you know, it can transfer the enumerator to another project and continue to list it later, what will happen if it continues the enumeration, and the compiler is illegally called permanently?
source share