473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Help - User control and serialization

Tom
I am having a really annoying issue with serialization and a .NET User
Control I am writing. For example, let's say I have a couple of classes in
my control - first class is like:

Public Class User
Private _UserName As String
Private _UserCity As String
<System.ComponentModel.CategoryAttribute("User Info")> _
Public Property UserName() As String
Get
Return _UserName
End Get
Set(ByVal Value As String)
_UserName = Value
End Set
End Property
<System.ComponentModel.CategoryAttribute("User Info")> _
Public Property UserCity() As String
Get
Return _UserCity
End Get
Set(ByVal Value As String)
_UserCity = Value
End Set
End Property
End Class

Then the second class is a collection of the first, as so:

<Serializable()> _
Public Class UserCollection
Inherits Collections.CollectionBase

Default Public Property Item(ByVal index As Integer) As User
Get
Return CType(List(index), User)
End Get
Set(ByVal Value As User)
List(index) = Value
End Set
End Property

Public Function Add(ByVal value As User) As Integer
Return List.Add(value)
End Function
...
... (more functions follow, such as IndexOf, etc)
...
End Class

Then, in my .NET User Control, I have the following:

Private _UserFields As New UserCollection()
<System.ComponentModel.DesignerSerializationVisibi lity(ComponentModel.Design
erSerializationVisibility.Content), _
System.ComponentModel.Description("User Information"), _
System.ComponentModel.CategoryAttribute("User Info")> _
Public ReadOnly Property UserCriteria() As UserCollection
Get
Return _UserFields
End Get
End Property

In the solution I also have a test project that uses the control (just so I
can test it).

This seems to work fine as long as I am in the designer; i.e. I can use the
property pages to add user collection data (i.e. Name, City). I can close
Visual Studio and reopen the solution; the items I added are still there.
However, if I go to run the solution (by clicking on the run icon or
selecting Debug-Start or pressing F5) I end up with the following errors:

1. The test form that is hosting the control (form1.vb) goes white in the
designer and shows the following error message:

"An error occured while loading the document. Fix the error, and then try
loading the document again. The error message follows: The designer cannot
be modified at this time."

This occurs even though the form seems to execute fine and the application
shows up on the screen. I close the application and go back to the VB.NET
IDE, then close and reopen form1.vb in the designer (to get rid of the white
screen). Then the following build error shows up:

2. "At least one element in the source array could not be cast down to the
destination array type."

3. And then, when I use the property page and look at my control collection,
NOTHING is there anymore (i.e. the items I added before are all gone).

I have found VERY FEW articles or examples on making a control and using a
collection classe for property pages; the one I did find basically came up
with the same errors. It is very probable that I am missing something or
not doing something right (maybe I need to read the serialized data or
something when I actually execute the program??) But I am at a loss at this
point. If I can't figure this out I will just have to allow runtime only
modification of my control, which is something I really don't want to do.

Anyone know what I am missing here? Or know of a good example of this being
done in a user control? Thanks in advance....

Tom
Nov 20 '05 #1
0 1993

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jeff T. | last post by:
Hello, I have an existing set of C# classes that encapsulate our application data. They are in a heirachy with each subclass defining more specific types of data. I would like to serialize these...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
8
by: Martin Horn | last post by:
Hi, I am trying to add extra functionality to the standard RichText control, but I've fallen at the first hurdle,can someone take a look at the following code and tell me why it fails to return...
2
by: Bob | last post by:
Just new at this, Vs 2005 Vb.net Created a new Windows control library User control project. Only 1 file UserControl1.vb No code or object in it at all yet except what was placed by default when...
1
by: Christo | last post by:
as part of a project at uni i have been asked to provide object persistance through files I have opted for serialization my question is quite simple when u use serialization is an object...
3
by: namewitheldbyrequest | last post by:
"The XML element 'EnableTheming' from namespace 'http://tempuri.org/' is already present in the current scope" I created a Web Service: I imported System.Data.SqlClient so I could access SQL...
1
by: Mihai Velicu | last post by:
I created a control library and i created a control.I can test it is ok.I added this control to a form .Run the form is ok also.After i modified the control to add some new features and i had some...
13
by: Marc | last post by:
The first part of the below writes the name and location of all buttons on a from to a text file. The second part reads that information back in and recreates the buttons. My problem is reading...
4
by: Mihai | last post by:
Hi ! I use VB.Net 2005. I created an inherited user control based on a previosly created user control.Everything is Ok . I can run this control with f5, everything is fine. When I close Visual...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.