CSFramework.AutoUpgrader 发布命令升级包出错:InvalidOperationException使用 XmlInclude 或 SoapInclude 特性静态指定非已知的类型
CSFramework.AutoUpgrader 发布命令升级包出错:InvalidOperationException使用 XmlInclude 或 SoapInclude 特性静态指定非已知的类型
扫一扫加微信
InvalidOperationException: 不应是类型 CSFramework.AutoUpgrader.CmdDeleteFile。使用 XmlInclude 或 SoapInclude 特性静态指定非已知的类型。
C# Code:
/// <summary>
/// 序列化对象
/// </summary>
/// <param name="o">对象</param>
/// <param name="outFile">持久化对象文件</param>
/// <returns></returns>
public static bool Serialize(object o, string outFile)
{
using (StringWriter sw = new StringWriter())
{
XmlSerializer xz = new XmlSerializer(o.GetType());
xz.Serialize(sw, o);
File.WriteAllText(outFile, sw.ToString(), Encoding.UTF8);
}
return true;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// 序列化对象
/// </summary>
/// <param name="o">对象</param>
/// <param name="outFile">持久化对象文件</param>
/// <returns></returns>
public static bool Serialize(object o, string outFile)
{
using (StringWriter sw = new StringWriter())
{
XmlSerializer xz = new XmlSerializer(o.GetType());
xz.Serialize(sw, o);
File.WriteAllText(outFile, sw.ToString(), Encoding.UTF8);
}
return true;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
解决方案:
在PackageFile类添加XmlInclude特性,静态指定该类需要序列化的类型。
C# Code:
/// <summary>
/// 升级包实体类,用于序列化持久存储在数据库
/// </summary>
[Serializable]
[XmlInclude(typeof(PackageFileItem))]
[XmlInclude(typeof(CmdDeleteFile))]
[XmlInclude(typeof(CmdRunProgram))]
public class PackageFile
{
private string _PackingNo;
private string _Remark;
private List<PackageFileItem> _Files;
/// <summary>
/// 支持Serializable特性的默认无参数构造器
/// </summary>
public PackageFile()
{ }
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// 升级包实体类,用于序列化持久存储在数据库
/// </summary>
[Serializable]
[XmlInclude(typeof(PackageFileItem))]
[XmlInclude(typeof(CmdDeleteFile))]
[XmlInclude(typeof(CmdRunProgram))]
public class PackageFile
{
private string _PackingNo;
private string _Remark;
private List<PackageFileItem> _Files;
/// <summary>
/// 支持Serializable特性的默认无参数构造器
/// </summary>
public PackageFile()
{ }
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
MSDN关于XmlIncludeAttribute的定义如下:允许 XmlSerializer 在它序列化或反序列化对象时识别类型。
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网