When an instance of a
DataSet typed object is serialized
when multiple threads are accessing the same instance synchronously, a
System.NullReferenceException exception may occur. The typical call stack is similar to the
following:
at System.Data.DataTable.System.Runtime.Serialization.ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
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.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)
This problem occurs when the
DataTable typed object does not have
the
DataSet member set to an instance of a
DataSet typed
object
Back to the top
This problem occurs because the
GetObjectData method that serializes a
DataTable typed object uses specific
methods of the
DataSet class. If the
DataTable typed object does not have the
DataSet member set to an instance of a
DataSet typed object, the
DataTable typed object will temporarily add or remove the
DataSet object.
However, the addition or removal of this temporary
DataSet object cannot be
performed synchronously.
Back to the top
To work around this problem, you can add a
DataSet member to the
DataTable typed object. The
DataSet member is set to an instance of the
DataSet typed
object. For example, locate the following line of code.
myTable = new DataTable("Names");Then add the following lines of code after the previous code.
DataSet myDS = new DataSet("MyDataSet");
myDS.Tables.Add(myTable);
Back to the top
Microsoft has confirmed that this is a bug in the Microsoft
products that are listed in the "Applies to"
section.
Back to the top
For more information about the
DataTable class, visit the
following Microsoft Developer Network (MSDN) Web site:
Back to the top