Cannot Add control to form(无法将控件添加到表单)
问题描述
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
这篇关于无法将控件添加到表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法将控件添加到表单
基础教程推荐
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01