Results 1 to 4 of 4

Thread: .Net Framework 3.5

  1. #1

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    .Net Framework 3.5

    A change in the .net framework version has become necessary for my project and i'm running into some issues with changing a usercontrol. I narrowed done my code and got to just the bare minimum to make the error.

    Code:
    Public Class UserCTest
        Private mMyCollection As Collection = New Collection
    
        Public Property MyCollection As Collection
            Get
                Return mMyCollection
            End Get
            Set(ByVal value As Collection)
                mMyCollection = value
            End Set
        End Property
    End Class
    As you can see i've got a collection property in the uc. Okay, so i run my project with a new UserCTest control and get two errors which read:

    Code:
    Could not find a type for a name.  The type name was 'Microsoft.VisualBasic.Collection, Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f11d50a3a'. Line 2659, position 5.
    And this which seems like it's being cause by the first one:

    Code:
    Unable to open file '...\Solution Folder\Project Folder\obj\x86\Debug\WindowsApplication1.Form1.resources': The system cannot find the file specified.
    All the other properties in my uc are fine so it's just this one which causes an error. As you can see from the error message the problem is in the form resource file in the place where the collection data is stored. I did a test to see if there's a problem with any property that is saved in the .resx file like this

    Code:
    Public Class UserCTest
        Private mMyImage As Image
    
        Public Property MyImage As Image
            Get
                Return mMyImage
            End Get
            Set(ByVal value As Image)
                mMyImage = value
            End Set
        End Property
    End Class
    It worked so as far as i know the problem is only with collections.
    Hooked for good.

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

    Re: .Net Framework 3.5

    Never, never, NEVER use that Collection class. It is a hold-over from VB6 and exists really just to support upgraded VB6 code. It should never be used in new VB.NET code. If you want a property that is a collection type then it should either be a System.Collections.Generic.List(Of T) or your own class derived from the System.Collections.ObjectModel.Collection(Of T) class.

    Also, such a collection property should never be read/write but rather always read-only. Can you think of any collection property in the .NET Framework that is read/write? Such a property should look like this:
    vb.net Code:
    1. Private _things As New List(Of Thing)
    2.  
    3. Public ReadOnly Property Things() As List(Of Thing)
    4.     Get
    5.         Return _things
    6.     End Get
    7. End Property
    or, with lazy-loading:
    vb.net Code:
    1. Private _things As List(Of Thing)
    2.  
    3. Public ReadOnly Property Things() As List(Of Thing)
    4.     Get
    5.         If _things Is Nothing Then
    6.             _things = New List(Of Thing)
    7.         End If
    8.  
    9.         Return _things
    10.     End Get
    11. End Property
    That's basically how every collection property in the .NET Framework is implemented, e.g. DataSet.Tables, DataTable.Rows, DataTable.Columns, Control.Controls, MenuStrip.Items, ToolStripMenuItem.DropDownItems, etc, etc.
    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
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Re: .Net Framework 3.5

    Never, never, NEVER use that Collection class. It is a hold-over from VB6 and exists really just to support upgraded VB6 code. It should never be used in new VB.NET code.
    Thanks, i'm glad to know that. I was using it because it was used in vb6. The reason why i was trying to use a collection is that i'd like to make my own imagelist which can hold large images with different sizes. Is there a way to get the normal image list to have large images?

    I was managing with a collection in the 4.0 framework just fine. When you make a collection property it saves it in the resources and looks like this in the designer:

    Code:
    Me.UserControl11.MyCollection = CType(resources.GetObject("UserControl11.MyCollection"), Microsoft.VisualBasic.Collection)
    But when i make a list of images property like this i see nothing in the form's designer saving the list. What would be the way of saving a list of images?

    Code:
        Private _things As New List(Of Image)
    
        Public Property Things() As List(Of Image)
            Get
                Return _things
            End Get
            Set(ByVal value As List(Of Image))
                _things = value
            End Set
        End Property
    Hooked for good.

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: .Net Framework 3.5

    Quote Originally Posted by cheesebrother View Post
    What would be the way of saving a list of images?
    You could save/load a list of bitmaps in a single file, see the top answer by JohnWein on MSDN forums here.

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