Thursday, August 28, 2003 - Posts

Bug in 1.0 and 1.1 compiler.

Richard Blewett, a develop mentor, points out to a Nasty Bug in 1.0 and 1.1 Compiler.

Here's the message.

The code below executes both the if and the else in release build with optimization turned on

    class DisposableClass : IDisposable
    {
        public void Dispose()
        {
        }
    }

    class Class1
    {
        static void Main(string[] args)
        {
            try
            {
                using ( new DisposableClass() )
                {
                    try
                    {
                        if ( args.Length == 0 )
                        {
                            Console.WriteLine("IN THE IF");
                            using ( new DisposableClass() )
                            {
                            }
                        }
                        else
                        {
                            Console.WriteLine("IN THE ELSE");
                            using ( new DisposableClass() )
                            {
                            }
                        }
                    }
                    catch ( Exception )
                    {
                    }
                }
            }
            catch ( Exception )
            {
            }
            Console.WriteLine("ending called");
        }
    }

commenting out the using block in the if block or putting code after the using block in the if resolves the problem.