SYMPTOMS
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
WORKAROUND
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);