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 (903645)



The information in this article applies to:

  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft ADO.NET (included with the .NET Framework 1.1)
  • Microsoft ADO.NET (included with the .NET Framework) 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("Names");
Then add the following lines of code after the previous code.
DataSet myDS = new DataSet("MyDataSet");
myDS.Tables.Add(myTable);

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

REFERENCES

For more information about the DataTable class, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:3/10/2006
Keywords:kberrmsg kbtshoot kbBug KB903645 kbAudDeveloper