Compiler doesn't accept correct syntax

When I was writing code which should convert an icon into a bitmap, I discovered the following bug:

IT's not possible to compile the following line:

New Icon("MyIcon.ICO", 16, 16).ToBitmap().Save("MyIcon.bmp", Imaging.ImageFormat.Bmp)

must be a bug, doesn't it?

PS: it works with the with-operator:

With New Icon("..\..\Resources\Icons\ViewIcon.ICO", 16, 16)
.ToBitmap.Save("..\..\Resources\Icons\ViewIcon.bmp", Imaging.ImageFormat.Bmp)
End With
best regards,
Gerhard

[502 byte] By [GerhardZehetbauer] at [2008-2-20]
# 1
I think the issue is that it is not legal to start a line with the New keyword, regardless of what else the code does.
jmcilhinney at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
You want to be careful with that line anyway as you are not disposing of the icon nor of the bitmap, therefore leaking resources. You should really wrap these with a Using statement, ie:


Using ico as New Icon("MyIcon.ICO", 16, 16)
Using bmp as Bitmap = ico.ToBitmap()
bmp.Save("MyIcon.bmp", Imaging.ImageForm.Bmp)
End Using
End Using

DavidM.Kean at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

A curious exception being if you use "call" (which I'd advise against, but am demonstrating here for knowledge's sake):

call (new Class1).Gettype()

AlexMoura at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...