Home All Groups Group Topic Archive Search About

The generic type 'System.Collections.ObjectModel.Collection`1' was used with the wrong number of gen

Author
27 Mar 2007 1:39 PM
svkuery
Has there been any resolution to this?

I am seeing the same problem.

The code seems to run ok but while I am stepping through it while
debugging VS shows the value of count in my watch window as this
error:

{"The generic type 'System.Collections.ObjectModel.Collection`1' was
used with the wrong number of generic arguments in assembly 'mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.":"System.Collections.ObjectModel.Collection`1"}
Integer

Like I said the code seems to be running ok but I am concerned that
there is an underlying problem.

Basically I have an abstract base class that derives from
System.Collections.ObjectModel.Collection(Of T).

I then have classes that derive from my base class.

Any thoughts?

Author
28 Mar 2007 7:05 PM
svkuery
Here is some code (in VB.NET) to go along with the problem.

'setup the following types:

Public Interface IStyle

End Interface

Public Interface IColor
    Inherits IStyle

End Interface

Public Class Red
    Implements IColor

End Class

Public Class Blue
    Implements IColor

End Class

Public Class Green
    Implements IColor

End Class

Public MustInherit Class StyleCollection(Of T As IStyle)
    Inherits System.Collections.ObjectModel.Collection(Of T)

    Public ReadOnly Property Test() As Integer
        Get
            Dim c As Integer

            c = Me.Count

            c = Me.Items.Count

            Return c
        End Get
    End Property

End Class

Public Class ColorCollection
    Inherits StyleCollection(Of IColor)

End Class

'Instantiate a ColorCollection and add some colors to it

        Dim colors As New ColorCollection

        Dim r As New Red
        Dim b As New Blue
        Dim g As New Green

        colors.Add(r)
        colors.Add(b)
        colors.Add(g)

Set a break point in the Test() property and step through the code.
Take a look at Me.Count & Me.Items in the watch window.  Instead of
the value, you should see the error:

{"The generic type 'System.Collections.ObjectModel.Collection`1' was
used with the wrong number of generic arguments in assembly 'mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.":"System.Collections.ObjectModel.Collection`1"}
System.Collections.Generic.IList(Of T)

Keep in mind the value is actually there and the code works ok.

AddThis Social Bookmark Button