A
Angelos Karantzalis
Hi guys,
I'm trying to load a class instance dynamically, and then cast it to it's
base type so I can use it in my app.
More specifically, I'm dynamically instantiating a
System.Web.UI.WebControls.RequiredFieldValidator and attempting to cast it
into an IValidator and/or a BaseValidator. Both casting attempts have
failed miserably, throwing an InvalidCastException ... how can it be i
cannot cast to the base class of my instance ???
More specifically, I load the Assembly directly from the System.Web.dll, and
create the RequiredFieldValidator instance using .CreateInstance(string
strClassName) on the Assembly.
I get back a perfectly good object, for which I'm using reflection to set
some properties before I cast it to it's base type (BaseValidator) and
return it from a method to the caller. upon casting it to the base type, I
get the InvalidCastException. This shouldn't be happening normally, and i'm
bangin' my head against a wall to find out what could be causing it ...
Could it be that the application uses a reference to the System.Web.dll, and
my own loader loads another instance of the assembly ? If this is it, how
could I work around it ?
Thanks a million,
Angel
O:]
I'm trying to load a class instance dynamically, and then cast it to it's
base type so I can use it in my app.
More specifically, I'm dynamically instantiating a
System.Web.UI.WebControls.RequiredFieldValidator and attempting to cast it
into an IValidator and/or a BaseValidator. Both casting attempts have
failed miserably, throwing an InvalidCastException ... how can it be i
cannot cast to the base class of my instance ???
More specifically, I load the Assembly directly from the System.Web.dll, and
create the RequiredFieldValidator instance using .CreateInstance(string
strClassName) on the Assembly.
I get back a perfectly good object, for which I'm using reflection to set
some properties before I cast it to it's base type (BaseValidator) and
return it from a method to the caller. upon casting it to the base type, I
get the InvalidCastException. This shouldn't be happening normally, and i'm
bangin' my head against a wall to find out what could be causing it ...
Could it be that the application uses a reference to the System.Web.dll, and
my own loader loads another instance of the assembly ? If this is it, how
could I work around it ?
Thanks a million,
Angel
O:]