Deserializing a DataSet

I’ve been given a DataTable, and I’m trying to read it into Unity. I’ve been given some C# code to help out with it, but no good – it’s still erroring out, and I’m not quite sure how to fix it, or really where I should go to learn more. Suggestions welcome.

Code:

		DataSet ds;
		BinaryFormatter bf = new BinaryFormatter();
		FileStream fs = new FileStream("Assets/SampleModelSerialized.dat", FileMode.Open);
		
		try
		{
			ds = bf.Deserialize(fs) as DataSet;
		}
		catch (Exception err)
		{
			throw;
		}
		finally
		{
			fs.Close();
		}

Error:

InvalidCastException: Cannot cast from source type to destination type.

Ok, problem solved. The issue was fixed by changing the line

DataSet ds;

into

System.Data.DataSet ds = new System.Data.DataSet();

I’m not sure why it matters that I declare it using System.Data.Dataset, instead of just Dataset (especially considering I’m already using the System.Data namespace), but apparently it does, and now things are working just fine. Note that the below does not work:

DataSet ds = new DataSet();