473,748 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Property assignment causes strange designer-generated code

Yesterday Visual Studio gave me a strange error both at compiletime and at
designtime that had no obvious connection to anything I had changed recently.
After some effort tracking down the problem I discovered first a workaround,
then the real cause of the problem. I would like to understand why what I am
doing is frowned upon by Visual Studio and how to do this properly.

My application is in one solution; supporting libraries including custom
controls in another. I am using C# in VS2008 and compiling to .NET 2.0 on
WinXP.

These are the compiletime errors:
############### ############
Error 1 Invalid Resx file. Type could not be read from the data in line
169, position 5. The type's internal structure may have changed. Either
implement ISerializable on the type or provide a type converter that can
provide a more reliable conversion format, such as text or an array of bytes.
The conversion exception was: The constructor to deserialize an object of
type 'CleanCodeContr ols.Support.Con nectionDetails' was not found. File:
MainForm.resx

Error 2 SerializationEx ception: Type could not be read from the data in
line 169, position 5. The type's internal structure may have changed.
Either implement ISerializable on the type or provide a type converter that
can provide a more reliable conversion format, such as text or an array of
bytes. The conversion exception was: The constructor to deserialize an
object of type 'CleanCodeContr ols.Support.Con nectionDetails' was not found.
XmlException: Type could not be read from the data in line 169, position 5.
The type's internal structure may have changed. Either implement
ISerializable on the type or provide a type converter that can provide a more
reliable conversion format, such as text or an array of bytes. The
conversion exception was: The constructor to deserialize an object of type
'CleanCodeContr ols.Support.Con nectionDetails' was not found. Line 169,
position 5.
############### ############

The visual designer manifests essentially the same error:
############### ############
The constructor to deserialize an object of type
'CleanCodeContr ols.Support.Con nectionDetails' was not found.
############### ############

These errors appeared because of this designer-generated statement in
MainForm.Design er.cs...
############### ############
new
CleanCodeContro ls.Support.Conn ectionDetailsCo llection().Add( ((CleanCodeCont rols.Support.Co nnectionDetails )(resources.Get Object("leftSql Editor.Configur ationList"))));
############### ############

That line was embedded in a set of statements initializing a custom control
inside InitializeCompo nent; here's some context. Instead of assigning to the
ConfigurationLi st property it created this unusual line.
############### ############
this.leftSqlEdi tor.AutoExecute Mode = false;
this.leftSqlEdi tor.AutoHighlig htMode = false;
this.leftSqlEdi tor.CommandTime out = 60;
new
CleanCodeContro ls.Support.Conn ectionDetailsCo llection().Add( ((CleanCodeCont rols.Support.Co nnectionDetails )(resources.Get Object("leftSql Editor.Configur ationList"))));
this.leftSqlEdi tor.ContainerTe st = false;
this.leftSqlEdi tor.CsvPath = ".";
this.leftSqlEdi tor.DbConfigura tionName = "--";
this.leftSqlEdi tor.DiagLabel = "LeftSqlEditor" ;
this.leftSqlEdi tor.Dock = System.Windows. Forms.DockStyle .Fill;
this.leftSqlEdi tor.LocalMode = false;
############### ############

Corresponding to this was a section in the MainForm.resx file:
############### ############
<data name="leftSqlEd itor.Configurat ionList"
mimetype="appli cation/x-microsoft.net.o bject.binary.ba se64">
<value>--- encoded binary data here --- </value>
</data>
############### ############

By deleting the line in MainForm.Design er.cs and deleting the <dataelement
in the MainForm.resx file, I could then compile successful and open the form
in visual designer. However, everytime I re-display the form in the visual
designer those code chunks are inserted again.

I digged deeper to determine why those lines were being generated all of a
sudden, because I had not changed anything related to the serialization or
structure of ConnectionDetai ls. I traced it to the line indicated with arrows
below (the ConfigurationLi st assignment inside this ContainerTest property)
of my SqlEditor custom control. leftSqlEditor is an instance of SqlEditor.
Removing the assignment to the ConfigurationLi st property removes the
generation of the above offending code by the visual designer.

############### ############
public bool ContainerTest
{
get { return containerTest; }
set
{
containerTest = value;

// signal to fill unbound DataGridView
dataGridView.Co ntainerTest = containerTest;

// provide a default connection to get bound data as well
>>>> ConfigurationLi st = new ConnectionDetai lsCollection {
new ConnectionDetai ls
{
ConfigName = "sqlExpress ",
ConnectionStrin g =
@"Data Source=.\SQLEXP RESS;Initial
Catalog=Adventu reWorks;"+
@"Integrated Security=True;P ersist Security
Info=True",
DbType = ConnectionStrin gManager.DBType s.SqlServer
}
};

DbConfiguration Name = "sqlExpress ";
}
}
private bool containerTest = false;

public ConnectionDetai lsCollection ConfigurationLi st
{
get { return configurationLi st; }
set
{
configurationLi st = value;
UpdateForChange dConfigList();
}
}
private static ConnectionDetai lsCollection configurationLi st;

############### ############
Here are the relevant code highlights of the object that is apparently
having serialization problems, though this code has been working fine even
with the Properties/Settings page for over 6 months. I can, for instance, go
to the Properties/Settings page of the application, click on the ellipsis for
this setting, and VS invokes a collection editor to allow manipulation of the
collection without complaint. My understanding was that this uses the
serialization in question.

############### ############
namespace CleanCodeContro ls.Support
{
public class ConnectionDetai lsCollection : Collection<Conn ectionDetails>
{
// empty
}
[Serializable]
public class ConnectionDetai ls : ICloneable, ISerializable
{

public ConnectionDetai ls(string configName) { this.configName =
configName; }

public ConnectionDetai ls() { }

public void GetObjectData(S erializationInf o info, StreamingContex t context)
{
info.AddValue(" ConfigName", configName);
info.AddValue(" ConnectionStrin g", connectionStrin g);
info.AddValue(" DbType", dbType);
info.AddValue(" RememberPasswor d", rememberPasswor d);
info.AddValue(" Description", description);
}
}
}
############### ############
So why does my particular sequence of code generate these misbehaving lines
of code, and why are they misbehaving? Or to cut to the chase: what could I
do to fix this?
Jul 2 '08 #1
6 3342
Thanks for the information, but it did not fix the issue.

Adding the first item:
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]

changed the generated code from:
new
CleanCodeContro ls.Support.Conn ectionDetailsCo llection().Add( ((CleanCodeCont rols.Support.Co nnectionDetails )(resources.Get Object("leftSql Editor.Configur ationList"))));
to:

this.leftSqlEdi tor.Configurati onList.Add(((Cl eanCodeControls .Support.Connec tionDetails)(re sources.GetObje ct("leftSqlEdit or.Configuratio nList"))));

Next, I added this serialization constructor (with a couple modifications to
your code to get it to compile):

protected ConnectionDetai ls(Serializatio nInfo info, StreamingContex t
context)
{
configName = info.GetString( "ConfigName ");
connectionStrin g = info.GetString( "ConnectionStri ng");
dbType = (ConnectionStri ngManager.DBTyp es)Enum.Parse(
typeof(Connecti onStringManager .DBTypes),
info.GetString( "DbType"));
rememberPasswor d = info.GetBoolean ("RememberPassw ord");
description = info.GetString( "Descriptio n");
}

And finally I added the SetType at the top of GetObjectData.

Now attempting to open the form in the designer yields this error:

"Method 'CleanCodeContr ols.Support.Con nectionDetailsC ollection.Add' not
found. "

My ConnectionDetai lsCollection class, as a reminder is just this empty class
definition:

public class ConnectionDetai lsCollection : Collection<Conn ectionDetails>
{
// empty
}

So are we getting closer to a solution? My understanding of the connections
for serialization is weak.
Jul 7 '08 #2
Hi Michael,

Thank you for your reply!
Next, I added this serialization constructor (with a couple modifications
to your code to get it to compile):

I didn't know the type of the DbType property and I assumed it as the type
of String. Thank you for showing us how you correct this line of code!
Now attempting to open the form in the designer yields this error:
"Method 'CleanCodeContr ols.Support.Con nectionDetailsC ollection.Add' not
found. "

Please delete the custom control from the Form and delete the item
"leftSqlEditor. ConfigurationLi st" from the form.resx file first. Re-build
the project and re-open the form in the designer and add the custom control
onto the form to see if the problem still exists.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 8 '08 #3
Rebuilding as you indicated seems to have cleared up the issue.
As a final question on this topic, could you point me to the MSDN pages that
describe these pieces necessary for proper serialization?

I looked through "Introducin g XML Serialization"
(http://msdn.microsoft.com/en-us/libr...hh(VS.80).aspx)
but I cannot find where it talks about any of the three points you itemized
to fix my problem.

Thanks!
Jul 10 '08 #4
Hi Michael,

Thank you for your reply!

As for the first point, properties that do not have a
DesignerSeriali zationVisibilit yAttribute will be treated as though they
have a DesignerSeriali zationVisibilit yAttribute with a value of Visible.
For a property of type collection, a private variable of type collection
will be created and initialized with the items configured at design time
first and then assigned to the public collection property within the
InitializeCompo nent method.

In your scenario, you configure the ConfigurationLi st property within the
set accessor of the ContainerTest property, so the form designer doesn't
know which property the private variable should be assigned to. At this
time, we can specify a DesignerSeriali zationVisibilit yAttribute with a
value of Content to address the problem.

The following MSDN document may help:
'How to: Serialize Collections of Standard Types with the
DesignerSeriali zationVisibilit yAttribute'
http://msdn.microsoft.com/en-us/library/ms171833.aspx

As for the second point, you implement the ISerializable interface for the
ConnectionDetai ls class, so the value of this property will be serialize
and stored in the form's resx file. When the form is re-opened, a design
time error occurs. So it's obvious that something is wrong when the form
designer is trying to construct instances of the
ConnectionDetai lsCollection class.

There's a comment "The ISerializable interface implies a constructor with
the signature constructor (SerializationI nfo information, StreamingContex t
context). " in the following MSDN document that explains this exactly:
http://msdn.microsoft.com/en-us/libr...zation.iserial
izable.aspx

As for the third point, after I configured the ConfigurationLi st property
in the designer and compile the project, I found that the value under the
Type column of the item "leftSqlEditor. ConfigurationLi st" within the
form.resx is null. So the type of the resource item is missing.

The sample in the
"http://msdn.microsoft. com/en-us/library/system.runtime. serialization.i seria
lizable.aspx" shows that we should call the SerializationIn fo.SetType
method to set the Type of the object to serialize in the
ISerializable.G etObjectData implementation.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 11 '08 #5
Thank you, Linda. The information you provided has been very enlightening!
Jul 11 '08 #6
You're welcome, Michael!

If you have any other questions in the future, please don't hesitate to
contact us. It's always our pleasure to be of assistance.

Have a nice day!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 14 '08 #7

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

Similar topics

2
1950
by: Aaron | last post by:
Hi, I've seen javascript code where a constructor function is passed an argument "document", and inside the function itself the assignment "this.document = document;" is made. This is the code (or the part necessary for the example): function ToggleButton(document) { ToggleButton.images = new Array(4); for(i=0;i<4;i++) { ToggleButton.images = new
2
8925
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input onclick="javaScript:alert('document.forms(0)='+document.forms(0)); parent.myFunc(document.forms(0));" type="button" value="Open" name="Button" ID="Button"> The strange part is that the debug alert says that the document.forms(0) is an object så all seem to be well. But...
1
4014
by: John Chorlton | last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid creating many public properties on the form to do the same thing. At first I tried returning a DataViewRow. This worked fine until I reached the phone field on the parent table and the code Child form public DataRowView SelectedAddres ge ...
7
4443
by: Andrea Moro | last post by:
I'm writing my first windows control library. A simple textbox with some numeric facilities. Well, there is a strange thing that happen. I want to add a locked property. As many other property, because it's a default property, I must shadow it, but unfortunately, despite the other properties shadowed, for instance tabindex, locked continue to stay in design category also if I set it up to behaviour, and doesn't run my own code.
3
1492
by: ScottBH | last post by:
Discovered a fun one that I thought I should share, and hopefully catch Microsoft's attention to update some documentation. I'm a bit new to VB.NET, and was struggling with getting a combo box to work. I was attempting to take advantage of the cool way to load a combo box via a datasource, rather than the old VB6 way of adding selections. First I tried an array of objects. I had some issues with that that I suspect had a lot to do with...
11
2400
by: anongroupaccount | last post by:
What measures should be taken to avoid this sort of thing? class Base { }; class Derived1 : public Base { private: int i, j, k;
2
3336
by: Michel Lapointe | last post by:
Hi, I have a problem while creating a customized DataGridViewColumn with a custom property. The problem is that after defining the property, adding the column to my Datagridview and settings it's property to true it never get define in the ..designer files, it always revert back to the default value. Does anyone know a fix to this issue/bug?
1
2998
by: screamingtarget | last post by:
I'm using C# 2.0. I have a UserControl-based class that contains a set of controls that are TextBox-based. The number of controls defaults to 1, but it is a browsable property (NumFields) in the form designer and can be changed. I expose a FieldText property in the form designer without exposing the TextBox-based class. I'm using an array of strings as the FieldText property. However the FieldText property as displayed in form...
0
1219
by: jwwishart | last post by:
Hi, Weve been doing this sort of thing frequently in ASP.NET but now were working on a project in ASP.NET 2.0 and were having this very strange problem. With the following XHTML... <table style="width: 500px" cellpadding="2" cellspacing="0"> <tr>
8
1643
by: Ethan Kennerly | last post by:
Hello, There are a lot of Python mailing lists. I hope this is an appropriate one for a question on properties. I am relatively inexperienced user of Python. I came to it to prototype concepts for videogames. Having programmed in C, scripted in Unix shells, and scripted in a number of proprietary game scripting languages, I'm impressed at how well Python meets my needs. In almost all respects, it does what I've been wishing a...
0
8987
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9366
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.