User Control issue at design time

R

Roy Chastain

The following is all relevant to VS 8.0.50727.762 (SP.050727-7600)
I have .Net 3.0 installed along with the CTPs for WPF and WCF etc. I do NOT have Orcas installed.

I have created UserControl A
I have created UserControl B that has UserControl A on it
I have created UserControl C that has UserControl B on it.
I have a form F that has UserControl C on it.

User control B creates the following line of code in the designer.cs
this.A1.TicketConfiguration = ((KMS.Protocol.UTS.A)(resources.GetObject("A1.TicketConfiguration")));

This same line appears in UserControl C and in form F with the names changed as appropriate.
With these lines in place, the control or form will not display at design time. Instead I get the following where the control
should display.

<html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"><title></title><style>.ErrorStyle { font-family:
tahoma; font-size: 11 pt; text-align: left}.DetailsStyle { font-family: tahoma; font-size: 10pt; text-align: left;text-indent: 0;
word-spacing: 0; line-height: 100%; float: left; margin-top: 0; margin-bottom: 0}.StackStyleVisible { font-family: tahoma;
font-size: 10pt; text-align: left; margin-left: 20; text-indent: 0}.StackStyleHidden { display:none; font-family: tahoma;
font-size: 10pt; text-align: left; margin-left: 20; text-indent: 0}</style></head><body><DIV class="DetailsStyle"
width="100%"><table border="0" width="100%" id="table1" height="100%" cellspacing="0" cellpadding="0"><tr><td height="40"
bgcolor="#FF9999" width="8%" style="letter-spacing: 0" align="center"><img border="0" src="c:\temp\168639.tmp" width="35"
height="35" alt="ErrorImage" ></td><td height="40" bgcolor="#FF9999" width="91%" style="vertical-align: top; letter-spacing: 0"
align="left"><b><font size="2" face="Arial" fontsize="70%">One or more errors encountered while loading the designer. The errors
are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.</font><font size="2"
face="Arial"></font></b></td></tr><tr><td colspan="2" align="left" valign="top"><DIV id="div1" class="ErrorStyle"
width="100%"><span style="font-weight: 600"><br>Object of type 'KMS.Protocol.UTS.A' cannot be converted to type
'KMS.Protocol.UTS.A'. </span><br><a href="" id="details0">Hide</a><font color="#0000FF">&nbsp;&nbsp;&nbsp;&nbsp</font></DIV> </td>
</tr> <tr><td colspan="2" align="left" valign="top"><DIV id="div20" class="StackStyleVisible" width="100%"><br> at
System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)<br> at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager,
CodeAssignStatement statement)<br> at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager,
CodeStatement statement)</DIV></td></tr></table></div></body></html>

If I comment out the line in question, then the controls will display properly at design time. This line of code does not
adversly affect runtime. The code runs with or without it.

Questions
1) - What is the line of code actually trying to acomplish?
2) - What could be wrong.
3) - Is there something I can put on the control at design time that would prevent VS from generating this line.
 
L

Linda Liu [MSFT]

Hi Roy,

Based on my understanding, you have a WinForm application project developed
with VS2005. The project has UserControlA, UserControlB and UserControlC
and a Form in it. You add an instance of UserControlA on UserControlB, and
the line of code 'this.A1.TicketConfiguration =
((KMS.Protocol.UTS.A)(resources.GetObject("A1.TicketConfiguration")));' is
generated in the designer.cs file. At this time, the UserControlB couldn't
be opened in the designer properly. If I'm off base, please feel free to
let me know.

It seems that the problem is caused by the TicketConfiguration property of
UserControlA. What's the type of this property?

Since there're some custom types in your project that may cause the
problem, could you please create a simple project that could just reproduce
the problem and send it to me? To get my actual email address, remove
'online' from my displayed email address.

Thank you for your understanding and cooperation! I look forward to your
reply.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

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

Roy Chastain

I have created a relatively simple repro of the issue. It is a solution with 3 projects with the same structure as my failing
project.

In the sample as in the original problem TicketConfiguration is a property that accesses a simple class that is defined in another
project within the solution.

In this case, I completely built both the UserControls before I tried to place the on the form. When I placed the UserControl on
the form I received the CAST error as shown in the attached screen capture. The message indicates the same problem that I am
having when design mode does not display.

Here is the breakdown of the solution
Project - Data - Contains 2 classes that are serialized.
Project - UI - Contains 2 user controls.
1) - TicketUI - the 'base' UserControl. It has a public property called TicketConfiguration that is used to access the 'data'
class called Ticket that is in the Data project.
2) - TicketContainerUI - the UserControl that has TicketUI placed on its design surface. That is all it has.
Project - Driver - Has a windows forms application. I tried to drag TicketContainerUI to its design surface and received the cast
error that says "...cannot cast object of type 'KMS.MSTest.Data.Ticket' to type ' KMS.MSTest.Data.Ticket'..." This stack walk
back shows a line of code similar to my original post.

The email containing the solution and screen capture is on its way to you.
 
R

Roy Chastain

Linda,
I had not heard from you in a while. I was wondering if you were making any progress?
 
L

Linda Liu [MSFT]

Hi Roy,

Sorry that I forgot to update in the newsgroup when I sent you an email at
the fifth Sept. to your personal email box. It seems that you didn't
receive my email.

I post my reply in the email here.

Thank you for your reply and new finding! I think I find the real reason of
the problem.

The reason why you get the design time error is that the assembly version
has not changed between builds. The designer may not respond correctly to
some type requests if the version number does not change. To fix this,
change the build number in the project to:
[assembly: AssemblyVersion("1.0.0.*")]

(notice the asterisk at the end). This will increment the "build" number
after every build and will allow the designer to differentiate between
different loads of the same assembly and type.

Please try this out on your side to see if it solves the problem and then
let me know the result.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
R

Roy Chastain

Yes, I received that email and I replied to it that day.

Changing the Version does not fix the problem. In fact the original
problem solution does have the version number changing on every build
as you have suggested.


Hi Roy,

Sorry that I forgot to update in the newsgroup when I sent you an email at
the fifth Sept. to your personal email box. It seems that you didn't
receive my email.

I post my reply in the email here.

Thank you for your reply and new finding! I think I find the real reason of
the problem.

The reason why you get the design time error is that the assembly version
has not changed between builds. The designer may not respond correctly to
some type requests if the version number does not change. To fix this,
change the build number in the project to:
[assembly: AssemblyVersion("1.0.0.*")]

(notice the asterisk at the end). This will increment the "build" number
after every build and will allow the designer to differentiate between
different loads of the same assembly and type.

Please try this out on your side to see if it solves the problem and then
let me know the result.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
L

Linda Liu [MSFT]

Hi Roy,

Thank you for your reply!

I perfomed more tests on your sample project and discovered that the
problem is actually caused by resource, i.e. the value of the
TicketConfiguration property of the TicketUI control is serialized and
stored in the TicketContainerUI.resx file.

It seems that once a value of the TicketConfiguration property is
serialized and stored in the resoucre, the resource maintains a copy of the
assembly that contains the definition of the Ticket class. If we make some
modification in the Data or UI project and rebuild the solution, the
designer obtains the new version of the assembly which is different from
that one maintained by the resource, thus cast exception occurs.

To solve the problem, we should prevent the TicketConfiguration property
from being serialized and stored in the resource. To do this, we could add
a DesignerSerializationVisibilityAttribute to the TicketConfiguration
property.

In addition, I recommend you to hide this property from the Properties
window because this property is not editable at design time and there're
other two properties called 'BinaryTicketAuthMode' and
'KerberosTargetAccount' in the TicketUI class that get or set the sub
properties of the TicketConfiguration property.

The following is the modified code:

[XmlIgnore]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Ticket TicketConfiguration
{....}

Please try it out on your side to see if it solves the problem and let me
know the result.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
R

Roy Chastain

That seems to have fixed the issue.
Thanks

Hi Roy,

Thank you for your reply!

I perfomed more tests on your sample project and discovered that the
problem is actually caused by resource, i.e. the value of the
TicketConfiguration property of the TicketUI control is serialized and
stored in the TicketContainerUI.resx file.

It seems that once a value of the TicketConfiguration property is
serialized and stored in the resoucre, the resource maintains a copy of the
assembly that contains the definition of the Ticket class. If we make some
modification in the Data or UI project and rebuild the solution, the
designer obtains the new version of the assembly which is different from
that one maintained by the resource, thus cast exception occurs.

To solve the problem, we should prevent the TicketConfiguration property
from being serialized and stored in the resource. To do this, we could add
a DesignerSerializationVisibilityAttribute to the TicketConfiguration
property.

In addition, I recommend you to hide this property from the Properties
window because this property is not editable at design time and there're
other two properties called 'BinaryTicketAuthMode' and
'KerberosTargetAccount' in the TicketUI class that get or set the sub
properties of the TicketConfiguration property.

The following is the modified code:

[XmlIgnore]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Ticket TicketConfiguration
{....}

Please try it out on your side to see if it solves the problem and let me
know the result.

Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top