Joe, as you can see from the bare bones version I posted it doesn't have to
do with using per se but rather having an empty try as the last statement of
an if statement

Regards

Richard Blewett
DevelopMentor

-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Reich, Joe
Sent: 28 August 2003 15:48
To: [EMAIL PROTECTED]
Subject: [inbox] Re: [ADVANCED-DOTNET] Nasty bug in 1.0 and 1.1 compiler

I don't have a compiler near me at the moment (web accessing from home)
but as *I* understand using blocks [1] they basically translate into a
try/finally where a special instance of the IDisposable object is
created for you and then always disposed in a finally block.  Well, at
least that's how I understand it to work "logically"...don't know if
implementation is precisely like that...but the gist should be close.

I *think* what is happening, is that the optimizer is having issues with
the nested using blocks because it's getting confused on the local
scoping of the specialInstance of the IDisposable object that is created
for you. I've heard of something similar happening within VB.NET as well
within For/Next blocks when trying to use an Exit For statement...

Nice catch though, I'll make be aware of it when programming in the
future.

> -----Original Message-----
> From: Richard Blewett
> Sent: Wednesday, August 27, 2003 12:35 PM
> To: [EMAIL PROTECTED]
> Subject: [ADVANCED-DOTNET] Nasty bug in 1.0 and 1.1 compiler
>
>
> The code below executes both the if and the else
> in release build with optimization turned on
>
> <code>
    <snipped />
> </code>
>
> commenting out the using block in the if block or putting
> code after the using block in the if resolves the problem
>
> Regards
>
> Richard Blewett
> DevelopMentor
>

[1]
class DisposableClass : Idisposable {public void Dispose(){}}

class Class1
{
  static void Main(string[] args)
  {
    try
    {
      try
      {
        DisposableClass specialInstance = new DisposableClass()

        try
        {
          if(args.Length == 0)
          {
            Console.WriteLine("IN THE IF");
            try
            {
              DisposableClass specialInstance = new DisposableClass()
              //nothing to do
            }
            finally
            {
              specialInstance.Dispose();
            }
          }
          else
          {
            Console.WriteLine("IN THE ELSE");
            try
            {
              DisposableClass specialInstance = new DisposableClass()
              //nothing to do
            }
            finally
            {
              specialInstance.Dispose();
            }
          }
        }
        catch(System.Exception) {}
      }
      finally
      {
        specialInstance.Dispose();
      }
    }
    catch(System.Exception) {}

    Console.WriteLine("ending called");
  }
}

===================================
This list is hosted by DevelopMentor®  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 19/08/2003
 
  

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 19/08/2003
 

===================================
This list is hosted by DevelopMentor®  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to