Generics and overriding

I'm having trouble when overriding methods that contain parameters with generic types that are inherited from the base type. Here is an example:



PublicClass BaseClass(Of T)
PublicClass ItemData
Protected mValueAs T
PublicReadOnlyProperty Value()As T
Get
Return mValue
EndGet
EndProperty
PublicSubNew(ByVal valueAs T)
mValue = value
EndSub
EndClass
PublicSubNew()
MyBase.New()
EndSub
PublicOverridableSub DoIt(ByVal itemAs ItemData)
EndSub
EndClass

PublicClass ControlClass(Of TAs Windows.Forms.Control)
Inherits BaseClass(Of T)
PublicSubNew()
MyBase.New()
EndSub
EndClass

PublicClass FormClass(Of TAs Windows.Forms.Form)
Inherits ControlClass(Of T)
PublicSubNew()
MyBase.New()
EndSub
EndClass

Now, if I attempt to override BaseClass.DoIt in FormClass by typing "Overrides " in the VS.NET 2005 Beta2 text editor then a Microsoft Visual Basic Compiler error occurs (i.e., the window that says, "Microsoft (R) Visual Basic Compiler has encountered a problem and needs to close. We are sorry for the inconvenience.")

Is this a known issue? Are there any workarounds?

Thanks,
Lance

[7369 byte] By [ljlevend] at [2008-1-19]
# 1
I'm not sure about whether this is a known issue, but have a look on the Microsoft Product Feedback Center and see if it is. If it hasn't been reported before, then I suggest you create a new bug report, including any steps required to reproduce it, perhaps even a Solution/Project containing the above code.
DavidM.Kean at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

No obvious issue, this seems to be valid scenario and works ok in whidbey... I'm testing using a late build and Changed the scenario around a little removed constraints to see the things were working ok.

This simple console app will ensure that that by looking at the output you can see that the override doit method is called for ControlClass and FormClass.

This compiles and runs fine...

Module Module1

Sub Main()
Dim Obj As New FormClass(Of Integer)
Obj.DoIt(1)

Dim obj1 As New ControlClass(Of Integer)
obj1.DoIt(1)

Dim objb As New BaseClass(Of Integer)
objb.DoIt(1)

Console.WriteLine("Success")
End Sub

Public Class BaseClass(Of T)
Public Overridable Sub DoIt(ByVal item)
Console.WriteLine(
"Base")
End Sub
End Class

Public Class ControlClass(Of T)
Inherits BaseClass(Of T)
Public Overloads Sub DoIt(ByVal x As T)
Console.WriteLine(
"Overrides for ControlClass")
End Sub
End Class

Public Class FormClass(Of T)
Inherits ControlClass(Of T)
Public Overloads Sub DoIt(ByVal x As T)
Console.WriteLine(
"Overrides for FormClass")
End Sub
End Class

End Module

spotty at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
Lance,
I tried on a recent build and I run into your issue.
I will follow up with the VB compiler devs.
As far as workaround, I found the following:
Type overrides in ControlClass and Override it
Then type overrides in Form Class and this time itworks
Then you can delete the overrides in ControlClass

Thanks for the post!!
Luca Dellamore - Visual Basic Testing Team

LucaDellamore-MS at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4
I tried the example you gave and syntactically there is nothing wrong with it and it does work although the problem appeared to do with the way the development environment was working and processing the lines being typed in.

I got it to work throuhg Cut/Paste your example rather than typing it but when entering it as though I was typing the example from scratch I did see the issue.

spotty at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5
FYI: the VB Devs fixed this bug, I tried in a recent build and now it works as expected.
Luca Dellamore - Visual Basic Testing Team
LucaDellamore-MS at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6
Thank you all for the info. I'm very glad to hear that the issue is fixed.

Lance

ljlevend at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...