IDataReader序列化错误

时间:2012-08-06 12:55:22

标签: asp.net serialization idatareader

我有一个ASP.NET页面,其中包含Gridview

我正在尝试将IDataReader对象绑定到网格。这个IDataReader对象是通过调用几层代码(实际上是构成Controller层和DB层的其他.ent项目dll)来分配的,然后最终被绑定到我的网格。

gridview1.Datasource = dr(博士是我的IDataReader),我没有看到任何问题。

但是在gridview1.Databind行我得到一个异常,异常对象中的细节如下:

  
    

{“在程序集'System.Data中键入'System.Data.Common.DbEnumerator',版本= 2.0.0.0,文化=中立,PublicKeyToken = b77a5c561934e089'未标记为可序列化。”}

  

我不确定应用程序出了什么问题。有什么想法或意见吗?

编辑1

添加stacktrace异常:

Server stack trace: 
   at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
   at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
   at System.Runtime.Remoting.Channels.CoreChannel.SerializeBinaryMessage(IMessage msg, Stream outputStream, Boolean includeVersions)
   at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.SerializeResponse(IServerResponseChannelSinkStack sinkStack, IMessage msg, ITransportHeaders& headers, Stream& stream)
   at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at System.Collections.IEnumerable.GetEnumerator()
   at System.Collections.IEnumerable.GetEnumerator()
   at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
   at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
   at System.Web.UI.WebControls.GridView.DataBind()
   at Drive.CampaignManager.CreateQuery.GridViewBind() 
   in Mycode.aspx.cs

从上面的堆栈跟踪中无法理解。

2 个答案:

答案 0 :(得分:1)

查看异常的堆栈跟踪。它将显示正在尝试序列化DbEnumerator的代码。

答案 1 :(得分:1)

通过阅读您发布的堆栈跟踪,您的层之间看起来有一些远程处理 - 这个代码是否运行在多台计算机上?像DataReaders(SqlDataReader,EntityDataReader等)这类不可序列化的类(或者如果你在美国是< - >可序列化的 :-))不能通过远程边界传递。

您需要一个不同的设计来完成这项工作,一个在代码层之间传递可序列化对象的设计。传递DataSet可能是使UI代码工作的最低摩擦方法,因为您只需替换

gridview1.Datasource = dr

gridview1.DataSource = ds