Hi.
Here my source code for testing:
class Program
{
    static void Main(string[] args)
    {
        bool result = Succeeded();
        Console.WriteLine(result.ToString());
    }

    private static bool Succeeded()
    {
        bool result = false;
        try
        {
            if (IsOk())
            {
                result = true;
                return result;
            }
        }
        finally
        {
            if (!result)
            {
                throw new Exception(); //imposssible for us
            }
        }
        return result;
    }

    private static bool IsOk()
    {
        return true;
    }
}
Reflector code is:
internal class Program
{
    // Methods
    private static bool IsOk()
    {
        return true;
    }

    private static void Main(string[] args)
    {
        Console.WriteLine(Succeeded().ToString());
    }

    private static bool Succeeded()
    {
        bool result = false;
        try
        {
            if (IsOk())
            {
                return true;
            }
        }
        finally
        {
            if (!result)
            {
                throw new Exception();
            }
        }
        return result;
    }
}
Look on the operator return in function Succeeded. As you can see optmizer has forgotten about a variable result at all. Therefore there will be an exception.
This logic error exists in all versions of .Net Reflector and other products which are based on this engine, since 2005.

I have detected it, studying Microsoft code.
private bool DoFileOk(IntPtr lpOFN);
Declaring Type: System.Windows.Forms.FileDialog 
Assembly: System.Windows.Forms, Version=2.0.0.0 
Yours faithfully, Pavel Fursov.
Pavel Fursov
0

Add comment

Please sign in to leave a comment.