简体   繁体   English

无法将控件添加到表单中

[英]Cannot Add control to form

I'm trying to add a Usercontrol to a form. 我正在尝试将Usercontrol添加到表单中。 The UserControl is in a separate project than the form, but is in the same solution. UserControl与表单位于一个单独的项目中,但是在同一个解决方案中。 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 ...." “无法创建组件MessageDisplayListControl 。错误消息如下:'System.Runtime.Serialization.SerializationException:在Assymbly AceXtremeNET中键入AceXtremeNET.Utilities.Message',版本= 10.0.0.273,......未标记为可序列化。在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. 该控件确实已添加到.Designer.cs ,但它不会显示在可视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. 每当我尝试构建时,我会得到多个错误,这些错误会产生与上面相同的基本错误,即'AceXtremeNET.Utilities.Message'不是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. 控件中的代码不依赖于此属性,因为它意味着purley作为get / set访问器。 Whenever I comment out the code, Everything appears to work correctly. 每当我注释掉代码时,Everything似乎都能正常工作。 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. 我之前提到过,我收到了另一个关于构建的错误,看起来这是唯一尝试序列化的Property。

--------- 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 阅读DesignerSerializationVisibility枚举

put this attribute on MessageList property 将此属性放在MessageList属性上

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

in this situation designer will lost user change in MessageList but if you set it to 在这种情况下,设计人员将丢失MessageList中的用户更改,但如果将其设置为

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

Designer will save the Property Content in Designer.cs of control host Designer会将属性内容保存在控制主机的Designer.cs中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM