Microsoft KB Archive/306726

= BUG: You receive an error message when you serialize a DBConcurrencyException object in ADO.NET 1.0 =

Article ID: 306726

Article Last Modified on 2/21/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1 Service Pack 1
 * Microsoft ADO.NET 1.1
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.1

-



This article was previously published under Q306726



This article refers to the following Microsoft .NET Framework Class Library namespace:
 * System.IO



SYMPTOMS
When you serialize a DBConcurrencyException object, the value of the Row property in the serialized version of the object is set to a null value and an exception occurs:

An unhandled exception of type 'System.NullReferenceException' occurred in .exe

Additional information: Object reference not set to an instance of an object.



CAUSE
Serialization support is not provided for DataRows in this version of Microsoft Visual Studio .NET.



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



Steps to reproduce the behavior
 Create a new Microsoft Visual C# .NET Console application.  Paste the following code: using System; using System.IO; using System.Collections; using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Data; using System.Data.SqlClient;

class CRepro {     public static void printObjectState(object obj) {           Console.WriteLine(&quot;=== &quot; + obj.GetType.FullName + &quot; ===&quot;); foreach(PropertyInfo prop in obj.GetType.GetProperties) {                 if (prop.DeclaringType == obj.GetType) {                       if (prop.GetValue(obj, null).GetType.GetInterface(&quot;ICollection&quot;) != null) {                             Console.WriteLine(&quot;=== &quot; + prop.GetValue(obj, null).GetType.FullName + &quot; ===&quot;); foreach(object collectionObj in (ICollection)prop.GetValue(obj, null)) {                                   printObjectState(collectionObj); }                       }                        else {                             Console.WriteLine(prop.Name + &quot;=&quot; + prop.GetValue(obj, null)); }                 }            }            Console.WriteLine(&quot;===============================&quot;); }     public static void genException {           try {                 SqlConnection conn = new SqlConnection(&quot;Data Source=WITSTER; User Id=xxxxxxxxxx; &quot; +                    &quot;Password=xxxxxxx; Database=Northwind&quot;); conn.Open; SqlCommand cmd = new SqlCommand(&quot;if exists(select * from sysobjects where name = 'test') &quot;+                   &quot;drop table test&quot;,conn); cmd.ExecuteNonQuery; cmd.CommandText = &quot;create table test (column1 int PRIMARY KEY CLUSTERED)&quot;; cmd.ExecuteNonQuery; cmd.CommandText = &quot;Insert into test values(1)&quot;; cmd.ExecuteNonQuery; SqlDataAdapter adapterA = new SqlDataAdapter(&quot;select * from test&quot;,&quot;Data Source=WITSTER; &quot;+                   &quot;User Id=sa; Password=Password1; Database=Northwind&quot;); SqlDataAdapter adapterB = new SqlDataAdapter(&quot;select * from test&quot;,&quot;Data Source=WITSTER; &quot;+                   &quot;User Id=sa; Password=Password1; Database=Northwind&quot;); DataSet dataSetA = new DataSet; DataSet dataSetB = new DataSet; SqlCommandBuilder builderA = new SqlCommandBuilder(adapterA); SqlCommandBuilder builderB = new SqlCommandBuilder(adapterB); adapterA.Fill(dataSetA); adapterB.Fill(dataSetB); dataSetA.Tables[0].Rows[0].Delete; adapterA.Update(dataSetA); dataSetB.Tables[0].Rows[0].Delete; adapterB.Update(dataSetB); }           catch (Exception e)            { printObjectState(e); Stream stream = File.Open(&quot;DBException.bin&quot;, FileMode.Create); BinaryFormatter bformatter = new BinaryFormatter; bformatter.Serialize(stream, e); stream.Close; // Deserialize stream = File.Open(&quot;DBException.bin&quot;, FileMode.Open); bformatter = new BinaryFormatter; Exception eAfter = (Exception)bformatter.Deserialize(stream); stream.Close; printObjectState(eAfter); }     }      public static int Main(String[] args) {           genException; return 0; } }                    Replace the data source, the user ID, and the password with the appropriate values. Press F5 to run the application.

Additional query words: DBConcurrencyException serialization kbreadme

Keywords: kbbug kbnofix kbsqlclient kbsystemdata kbreadme KB306726

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.