Major Problem downcasting from DataSets to Strongly typed datasets across dlls

Major Problem downcasting from DataSets to Strongly typed datasets across dlls

Post by Shay » Fri, 24 May 2002 23:37:41



   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
Typed DataSet.
        My Data Access Layer.dll knows nothing about my
Typed DataSet as it is not dependent on the DLL with the
Typed DataSet,
        so I use Reflection to create a concrete instance
of the Typed DataSet  using Assembly.Load(".dll") and
Assembly.GetType("concreteDatasET")
       and up cast it to a DataSet. I return the DataSet
to the
        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;

 
 
 

Major Problem downcasting from DataSets to Strongly typed datasets across dlls

Post by Shay » Sat, 25 May 2002 22:14:01


The cast exception occurred with Assembly.LoadFrom()
not Assembly.Load
I think the problem is the assembly is not signed with a
strong name and the assembly may be already LOADED and
Assembly.LoadFrom loads another instance of the same DLL

Quote:>-----Original Message-----

>   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
>Typed DataSet.
>        My Data Access Layer.dll knows nothing about my
>Typed DataSet as it is not dependent on the DLL with the
>Typed DataSet,
>        so I use Reflection to create a concrete instance
>of the Typed DataSet  using Assembly.Load(".dll") and
>Assembly.GetType("concreteDatasET")
>       and up cast it to a DataSet. I return the DataSet
>to the
>        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.LoadFrom("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;

>.