Wednesday, April 15, 2009

Workaround for changes to DataSet.Merge

We have a formerly open source system (nSurvey) running in production. None of us know too much about it, but we had to learn a little something when we recently upgraded a parent site to (finally) run against .Net framework 2.0. We tried to set the nSurvey site (which had to be a child site) to use framework 1.1 which is possible depending on what you have in the web.config of the parent site (parent as in parent in IIS). In our case, it had AJAX entries which have attributes causes framework 1.1 to blow up. As such we had to upgrade the nSurvey project to Visual Studio 2005 (framework 2.0).

DataSet.Merge changed between .Net frameworks 1.1 and 2.0 when DataSets have namespaces causing the merge to fail. There is a workaround, but the place where it's described on MS docs is totally freaking hosed and makes no sense.

Here is what we did which works fine for us (we're not about to go making big changes in this monster of a system):
string cachedNamespace = dataSet1.Namespace;
dataSet1.Namespace = string.Empty;

string cachedNamespaceChild = dataSet2.Namespace;
answerDataSet.Namespace = string.Empty;

dataSet1.Merge( dataSet2 );

dataSet1.Namespace = cachedNamespace;
dataSet2.Namespace = cachedNamespaceChild;