I have encountered a major problem with strongly typed
datasets. I can give you an example solution if you could
help me find the problem.
You may recognise this problem straight away.
The problem is :
My issue is I have a Console Application ".exe"
that references another DLL with a generated Typed DataSet.
I want to go to the DataBase with a stored proc
name and some parameters and return a result set into my
My Data Access Layer.dll knows nothing about my
Typed DataSet as it is not dependent on the DLL with the
so I use Reflection to create a concrete instance
of the Typed DataSet using Assembly.Load(".dll") and
and up cast it to a DataSet. I return the DataSet
Console executable and try to downcast it to the
strong typed data set and get an Invalid CastException.
When I do a quick watch on the DataSet I can
see its type is the concrete type and I can even
downcast it using quickwatch , which seems very weird.
I am working on a sample solution I could send out which
replicates this issue.....
Basically I think it might be repeatable by doing the
following lines of code:
Assembly assembly = Assembly.Load("non-dependent.dll");
Type type = assembly.GetType("namespace.TypedDataSet");
DataSet ds = (DataSet)Activator.CreateInstance(type);
//Invalid Cast Exception thrown
namespace.TypedDataSet tDS = (namespace.TypedDataSet)ds;