Object from Activator raise Invalid Cast.

  • Thread starter Alvaro E. Gonzalez V.
  • Start date
A

Alvaro E. Gonzalez V.

Hi;

I have a method that receives one of its parameters receives control of a base class that I made and
it´s inherited from UserControl. This parameter named as ctrl.

In the other parameters receives the necessary information in order to instantiating ctrl, This
control that inherits from this base class.

This instance I am doing with Activator.CreateIntance (assemblyName, typeName). This returns a
ObjectHandle.

Then invoke ObjectHandle.UnWrap() to get back the control and save instanced in a variable
System.Object, whenever I ctrl allowance of such an object to doing casting, And raise
"InvalidCastException"

Wath I do?

Tks.

Alvaro.
 
F

Family Tree Mike

It is a little unclear what you are trying to do. My interpretation of what
you are trying to do is that you want to create a new instance of ctrl. Here
is basically what the code (C#) should look like:

CtrlType ctrl = (CtrlType) Activator.CreateInstance("theAssembly",
"CtrlType");

As I said, I may be misunderstanding your problem. If so, please post the
code and point out where it fails.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top