Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 306726 - Last Review: February 21, 2007 - Revision: 3.4
BUG: You receive an error message when you serialize a DBConcurrencyException object in ADO.NET 1.0
This article was previously published under Q306726
This article refers to the following Microsoft .NET
Framework Class Library namespace:
On This Page
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
app_name.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 "Applies to" section of this article.
MORE INFORMATION
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("=== " + obj.GetType().FullName + " ===");
foreach(PropertyInfo prop in obj.GetType().GetProperties())
{
if (prop.DeclaringType == obj.GetType())
{
if (prop.GetValue(obj, null).GetType().GetInterface("ICollection") != null)
{
Console.WriteLine("=== " + prop.GetValue(obj, null).GetType().FullName + " ===");
foreach(object collectionObj in (ICollection)prop.GetValue(obj, null))
{
printObjectState(collectionObj);
}
}
else
{
Console.WriteLine(prop.Name + "=" + prop.GetValue(obj, null));
}
}
}
Console.WriteLine("===============================");
}
public static void genException()
{
try
{
SqlConnection conn = new SqlConnection("Data Source=WITSTER; User Id=xxxxxxxxxx; " +
"Password=xxxxxxx; Database=Northwind");
conn.Open();
SqlCommand cmd = new SqlCommand("if exists(select * from sysobjects where name = 'test') "+
"drop table test",conn);
cmd.ExecuteNonQuery();
cmd.CommandText = "create table test (column1 int PRIMARY KEY CLUSTERED)";
cmd.ExecuteNonQuery();
cmd.CommandText = "Insert into test values(1)";
cmd.ExecuteNonQuery();
SqlDataAdapter adapterA = new SqlDataAdapter("select * from test","Data Source=WITSTER; "+
"User Id=sa; Password=Password1; Database=Northwind");
SqlDataAdapter adapterB = new SqlDataAdapter("select * from test","Data Source=WITSTER; "+
"User Id=sa; Password=Password1; Database=Northwind");
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("DBException.bin", FileMode.Create);
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(stream, e);
stream.Close();
// Deserialize
stream = File.Open("DBException.bin", 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.
APPLIES TO
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft ADO.NET 1.1
- Microsoft Visual C# .NET 2002 Standard Edition
- Microsoft Visual C# .NET 2003 Standard Edition
- Microsoft .NET Framework 1.1
| kbbug kbnofix kbreadme kbsqlclient kbsystemdata KB306726 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please