Microsoft KB Archive/903645

= BUG: A System.NullReferenceException exception occurs when an instance of a DataSet typed object is serialized when multiple threads access the same instance of a DataSet typed object synchronously =

Article ID: 903645

Article Last Modified on 5/21/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft ADO.NET 1.1
 * Microsoft ADO.NET 1.0

-





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



CAUSE
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.



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(&quot;Names&quot;); Then add the following lines of code after the previous code. DataSet myDS = new DataSet(&quot;MyDataSet&quot;); myDS.Tables.Add(myTable);



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.

