Dynamically loading controls -> loosing type

  • Thread starter Thread starter Peter Zuber
  • Start date Start date
P

Peter Zuber

Hi NG

We want to load controls dynamically and create them on a WinForm. Doing so,
we seem to loose type information. The scenario is as follows: The class
MANCombobBox inherits from ComboBox and implements the interface
IReportDataSource.

This works:
Control c = new MANComboBox(); //MANComboBox inherits from ComboBox and
implements the interface IReportDataSource

MessageBox.Show( (c is IReportDataSource).ToString() ); //This
returns/displays true

Here we have the problem:
Assembly asm = Assembly.LoadFile("LookupControls.dll"); //loads the dll
which contains the MANComboBox control

Control control = (Control) asm.CreateInstance(fullControlName); //Pointing
with the mouse onto control, the IDE tells me, that control contains
something of type MANComboBox

MessageBox.Show( (control is
MAN.Framework.Win.MANReportLookupControls.MANComboBox).ToString() );
//returns false

Intellisense even shows me the methods of the implemented interface
IReportDataSource but during runtime an invalid cast exception is thrown.

Any hints?

Thanks for all the help we get

Cheers

Peter
 
Back
Top