XMLSerializer - 类型X的对象不能用于未类型的集合,例如ArrayLists。 [英] XMLSerializer - Objects of type X may not be used in un-typed collections, such as ArrayLists.

查看:48
本文介绍了XMLSerializer - 类型X的对象不能用于未类型的集合,例如ArrayLists。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XMLSerializer来序列化/反序列化自定义对象。这样做的目的是缓存webservice调用并基本上播放它。该对象存储类名称&需要调用的方法名称以及需要传递给方法的参数。参数使用ArrayList存储在自定义对象中(虽然我也尝试过一个Object数组)

这一直有效,直到我们需要将数据集作为参数之一传递。这会导致XMLSerializer发生InvalidOperationException:

生成XML文档时出错。

内部异常有以下消息:

类型System.Data.Dataset可能不在此上下文中使用。要使用System.Data.Dataset作为参数,返回类型或类或结构的成员,必须将参数,返回类型或成员声明为System.Data.Dataset类型(它不能是对象)。
System.Data.Dataset类型的对象不能用于未打包的集合,例如ArrayLists。


什么是处理这类事情的正确方法?

I am using the XMLSerializer to serialize/deserialize a custom object. The purpose of this is to cache a webservice call and basically play it back. The object stores the class name & method name that needs to be called and the parameters that need to be passed to the method. The parameters are store in the custom object using an ArrayList (though I've tried an array of Object as well)

This has worked until we needed to pass a dataset as one of the parameters. This cause an InvalidOperationException from the XMLSerializer:

There was an error generating the XML document.

The inner exception has the following message:

The type System.Data.Dataset may not be used in this context. To use System.Data.Dataset as a parameter, return type, or member of a class or struct, the parameter, return type, or member must be declared as type System.Data.Dataset (it cannot be object).
Objects of type System.Data.Dataset may not be used in un-typed collections, such as ArrayLists.


What is the proper way to handle something like this?

推荐答案

您应该尝试使用像List< T>这样的通用集合。而不是未打字的集合。
You should try using a generic collection like List<T> instead of an un-typed collection.


这篇关于XMLSerializer - 类型X的对象不能用于未类型的集合,例如ArrayLists。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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