我在VS2008中遇到以下Designer错误:

 Object of type 'Data.TimeLineChartedDay[]' cannot be
 converted to type 'Data.TimeLineChartedDay[]'.

???
public class TimeLineDisplay
{
    private List<TimeLineChartedDay> chartedDays = new List<TimeLineChartedDay>();

    public List<TimeLineChartedDay> ChartedDays
    {
        get { return chartedDays; }
        set { chartedDays = value;  }
    }
}

[Serializable]
public class TimeLineChartedDay
{
    private DateTime date;
    private int chartValue;

    public DateTime Date
    {
        get { return date; }
        set { date = value; }
    }

    public int ChartValue
    {
        get { return chartValue; }
        set { chartValue = value; }
    }

    public TimeLineChartedDay()
    {

    }
}

VS STACK:
    at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
    at System.Reflection.RtFieldInfo.InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean doVisibilityCheck, Boolean doCheckConsistency)
    at System.Reflection.RtFieldInfo.InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean doVisibilityCheck)
    at System.Runtime.Serialization.FormatterServices.SerializationSetValue(MemberInfo fi, Object target, Object value)
    at System.Runtime.Serialization.ObjectManager.CompleteObject(ObjectHolder holder, Boolean bObjectFullyComplete)
    at System.Runtime.Serialization.ObjectManager.DoNewlyRegisteredObjectFixups(ObjectHolder holder)
    at System.Runtime.Serialization.ObjectManager.RegisterObject(Object obj, Int64 objectID, SerializationInfo info, Int64 idOfContainingObj, MemberInfo member, Int32[] arrayIndex)
    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.RegisterObject(Object obj, ParseRecord pr, ParseRecord objectPr, Boolean bIsString)
    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObjectEnd(ParseRecord pr)
    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord pr)
    at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
    at System.Resources.ResXDataNode.GenerateObjectFromDataNodeInfo(DataNodeInfo dataNodeInfo, ITypeResolutionService typeResolver)
    at System.Resources.ResXDataNode.GetValue(ITypeResolutionService typeResolver)
    at System.Resources.ResXResourceReader.ParseDataNode(XmlTextReader reader, Boolean isMetaData)
    at System.Resources.ResXResourceReader.ParseXml(XmlTextReader reader)

在此错误之前,发生了以下事情:
我添加了一个自写控件。 VS崩溃,并显示以下消息:“类TimeLineChartedDay未标记为可序列化”。我发现这很奇怪,因为它是在另一台机器上编写的,该机器没有提示'Serializable'属性。我将属性添加到类中,偶然发现了前面提到的错误。

最佳答案

您的控件尝试在可能不应该序列化类实例时对其进行序列化。

您可能应该将[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]添加到公开TimeLineDisplay的属性中。

如需更具体的建议,请向我们展示您的控制权。

关于c# - 类型 'Data.TimeLineChartedDay[]'的对象不能转换为 'Data.TimeLineChartedDay[]'类型?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4452001/

10-17 02:13