Results 1 to 8 of 8

Thread: [2008] Method 'System.Collections.Generic.List`1[].Add' not found

  1. #1

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Resolved [2008] Method 'System.Collections.Generic.List`1[].Add' not found

    Greeting,

    I get the error below.

    Code:
    Method 'System.Collections.Generic.List`1[[Testing.Controls.UIMenuItem, Testing.Controls, Version=1.0.3183.23614, Culture=neutral, PublicKeyToken=null]].Add' not found
    So to describe the problem, I have a solution with following structure.

    Code:
    Testing.sln
        Testing.Controls (Class Library Project)
            UIMenuController (User Control)
            UIMenuItem (User Control, Designtime non visible)
            UIMenu (User Control, Designtime non visible)
        Testing.ClientBase (Class Library Project)
            FormBase (UIMenuController control added, UIMenuItem added to the collection in UIMenuController)
            FormData inherited from FormBase (another UIMenuItem added to the collection in UIMenuController)
    Error is at
    Code:
    Method 'System.Collections.Generic.List`1[[Testing.Controls.UIMenuItem, Testing.Controls, Version=1.0.3183.23614, Culture=neutral, PublicKeyToken=null]].Add' not found.   
      
    C:\Projects\Testing\Testing.ClientBase\FormData.Designer.vb   
    Line 28   
    Col 0
    Call stack is
    Code:
    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)   
    at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)   
    at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
    Now I can add as many UIMenuItems as I want in the FormBase with no problems but the moment I try to do that in any other form inherited from the FormBase it decides to throw me an error.

    It adds it fine but then when you compile and try to see the form then you get an error. I have searched up and down the net and haven't found any solution and since the properties of the UIMenuController are a normal collection I can't see where things are going wrong.

    I am attaching the whole solution for further inspection (It's created in Visual Studio 2008 with all projects set to use Framework 2.0). Any help would be greatly appreciated.
    http://www.codelake.com/ausshare/msdn/testing.zip

    Cheers
    Last edited by wrack; Sep 18th, 2008 at 07:02 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Method 'System.Collections.Generic.List`1[].Add' not found

    I'm not sure why that error is occurring but you shouldn't be using the List class for public properties anyway. You should be defining your own typed collection class. If you have a property that exposes a collection of UIMenuItem objects then its type should be a class of your own definition:
    vb.net Code:
    1. Public Class UIMenuItemCollection
    2.     Inherits System.Collections.ObjectModel.Collection(Of UIMenuItem)
    3. End Class
    You can then override or add members in that class if you need additional functionality. Try making that change and see if you still get the same issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Re: [2008] Method 'System.Collections.Generic.List`1[].Add' not found

    Thanks Jim.

    So the MenuItems property would be pointing to an instance of the UIMenuItemCollection correct?

  4. #4

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Re: [2008] Method 'System.Collections.Generic.List`1[].Add' not found

    Ok, I just tried this.

    Code:
        Private mUIMenuItemCollection As UIMenuItemCollection = New UIMenuItemCollection()
        <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
        Public ReadOnly Property MenuItems() As UIMenuItemCollection
            Get
                Return mUIMenuItemCollection
            End Get
        End Property
    
    <DesignTimeVisible(False)> _
    Public Class UIMenuItemCollection
        Inherits System.Collections.ObjectModel.Collection(Of UIMenuItem)
    
        Public Shadows Sub Add(ByVal item As Testing.Controls.UIMenuItem)
            MyBase.Add(item)
        End Sub
    End Class
    I not get this error which is pretty much the same but a little nicer. Method 'Testing.Controls.UIMenuItemCollection.Add' not found.

    Any ideas?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Method 'System.Collections.Generic.List`1[].Add' not found

    Why are you shadowing the Add method? The Collection(Of T) class already has an Add method that you inherit, hence you're being able to call MyBase.Add. Get rid of that method and see if you still get that error message. I'm guessing that you will and, if so, can you attach your project as it is now? Just attach it to your post.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Re: [2008] Method 'System.Collections.Generic.List`1[].Add' not found

    Quote Originally Posted by jmcilhinney
    Why are you shadowing the Add method? The Collection(Of T) class already has an Add method that you inherit, hence you're being able to call MyBase.Add. Get rid of that method and see if you still get that error message. I'm guessing that you will and, if so, can you attach your project as it is now? Just attach it to your post.
    I know it already has an add method but since I got an error saying it couldn't find it, I though I would expose it myself (just trying).

    Anyways attached in the solution.
    Attached Files Attached Files
    Last edited by wrack; Sep 17th, 2008 at 10:56 PM.

  7. #7

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Re: [2008] Method 'System.Collections.Generic.List`1[].Add' not found

    OK just for those who are curious, I have managed to fix this by signing the assembly containing the controls and have put it in a different diectory and added a reference to it from that directory and it all seems fine now.

    Thanks for your help Jim. I am using the CollectionClass now as you suggested.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Method 'System.Collections.Generic.List`1[].Add' not found

    All seems a bit weird, doesn't it? I'm glad you found a solution.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width