不能添加控制形成 [英] Cannot Add control to form

查看:224
本文介绍了不能添加控制形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个用户控件添加到表单。该用户控件是在比形式的单独的项目,但在相同的溶液中。我已经加入这个控制其他形式的过去,然而,有些东西已经改变了,我得到了以下错误:

  

无法创建组件 MessageDisplayListControl 。   该错误消息如下:   System.Runtime.Serialization.SerializationException:类型AceXtremeNET.Utilities.Message在Assymbly AceXtremeNET,版本= 10.0.0.273,......没有被标记为可序列化。在System.Runtime.Serialization.FormatterServices.InternalGetSerializableMember(RuntimeType型)的......

于是控制系统被添加到了.Designer.cs ,但是,它是不是在视觉界面显示。每次我试图构建,我得到的给予同样的基本误差与上述多个错误,认为AceXtremeNET.Utilities.Message'不是可序列化。

---------编辑------------------

我的控制有其出现的问题以下属性。

 公开的IList<消息> MessageList中的{{返回_getList();} {集合{_lostList(值);}}
 

没有code的控制取决于此属性的,因为它本来普尔雷作为一个get / set访问。 每当我注释掉code,一切看起来正常工作。否则,我可以在错误我上面提到的。我已经receieved另一个错误的构建正如我前面提到的,看来这是试图将序列化的唯一属性。

---------编辑(堆栈跟踪)------------------

 在System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType型)
在System.Runtime.Serialization.FormatterServices.GetSerializableMembers(类型类型的StreamingContext上下文)
在System.Runtime.Serialzation.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
在System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(类型的objectType,ISur​​rogateSelector surrogateSelector,的StreamingContext背景下,SerObjectInfoInit serObjectInfoInit,IFormatterConverter来换算,SerializationBinder粘合剂)
在System.Runtime.SerializationFormatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo objectInfo,NameInfo memberNameInfo,WriteObjectInfo memberObjectInfo)
...
 

---------编辑(控件属性)------------------

 公共MessageControl MessageDisplay {{返回messageControl1;}} //这是我创造了另一个用户控件。我已经没有这个控制的任何问题。
公共MessageListBox {{返回listBox1中; }}
公众诠释MessageCount {{返回MessageListBox.Items.Count; }}
公共BOOL ValidSelection {{返回(的SelectedIndex> = 0&功放;&放大器;的SelectedIndex< MessageCount); }}
公开信息SelectedMessage {{返回listBox1.SelectedItem的消息; }集合{MessageDisplay.Message =价值; }}
公众诠释的SelectedIndex {{返回listBox1.SelectedIndex; }集合{listBox1.SelectedIndex =价值; }}
 

解决方案

阅读<一个href="http://msdn.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibility.aspx">DesignerSerializationVisibility枚举

把这个属性在MessageList中的财产

  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
 

在这种情况下,设计师会失去用户的变化将MessageList 但如果你将其设置为

  [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
 

设计师将保存属性的内容,控制主机的Designer.cs

I'm trying to add a Usercontrol to a form. The UserControl is in a separate project than the form, but is in the same solution. I have added this control to other forms in the past, however, something has changed and I get the following error:

"Failed to create the component MessageDisplayListControl. The error message follows: 'System.Runtime.Serialization.SerializationException: Type AceXtremeNET.Utilities.Message' in Assymbly AceXtremeNET, Version=10.0.0.273,...... is not marked as serializable. at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMember(RuntimeType type) at ...."

The control does get added to the .Designer.cs, however, it is not displayed in the visual GUI. Everytime I try to build, I get multiple errors that give the same basic error as above, that the 'AceXtremeNET.Utilities.Message' is not Serializable.

--------- Edit ------------------

My control has the following property which appears to the problem.

public IList<Message> MessageList {get{return _getList();} {set {_lostList(value);}}

No code in the control is dependant on this property as it was meant purley as a get/set accessor. Whenever I comment out the code, Everything appears to work correctly. Otherwise I can the error I mentioned above. I have receieved another error on build as I mentioned before, and it appears this is the only Property that is trying to be Serialized.

--------- Edit (Stack Trace)------------------

at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialzation.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
at System.Runtime.SerializationFormatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)
...

--------- Edit (Control Properties)------------------

public MessageControl MessageDisplay {get{return messageControl1;}} // This is another user control I created.  I've not had any problems with this control.
public MessageListBox {get { return listBox1; } }
public int MessageCount { get { return MessageListBox.Items.Count; }}
public bool ValidSelection { get { return (SelectedIndex >= 0 && SelectedIndex < MessageCount); } }
public Message SelectedMessage { get { return listBox1.SelectedItem as Message; } set { MessageDisplay.Message = Value; } }
public int SelectedIndex { get { return listBox1.SelectedIndex; } set { listBox1.SelectedIndex = value; } }

解决方案

read about DesignerSerializationVisibility Enumeration

put this attribute  on MessageList property

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

in this situation designer will lost user change in MessageList but if you set it to

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

Designer will save the Property Content in Designer.cs of control host

这篇关于不能添加控制形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆