[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 :)
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:
Public Class UIMenuItemCollection
Inherits System.Collections.ObjectModel.Collection(Of UIMenuItem)
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.
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?
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?
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.
1 Attachment(s)
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.
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.
Re: [2008] Method 'System.Collections.Generic.List`1[].Add' not found
:sick: All seems a bit weird, doesn't it? I'm glad you found a solution.