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
- Notice
This email and any files transmitted with it are confidential. It is for the
use of the person to whom it is addressed only. If you have received this
email in error, please reply immediately.
It is the responsibility of the recipient to virus scan the information
provided before loading onto any computer.
Any views expressed in this message are those of the individual sender, except
where the sender specifically states them to be the views of Interactive
Business Systems.
===================================
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