0
Reply

problem casting from Control to Custom Control

CharlieJames

CharlieJames

Apr 11 2005 5:45 PM
1.7k
Plse help. I have a Custom Control (lets call it myCustomControl) which I dynamically load using Assembly.LoadFrom(). I can then instantiate Control objects using "aControl = (Control)AssemblyInstanceName.CreateInstance(classname)" (where AssemblyInstanceName is the name of an instance of the Assembly class) which uses the Assembly classes CreateInstance method and casts the result to a Control object. This seems to work fine, the web form shows my Custom Controls appearing. I do not appear to able to do "myCustomClassInstance = (myCustomClass)AssemblyInstanceName.CreateInstance(classname)" which I think should create the instance as a true myCustomClass. Also I can't then cast the createdinstances from Control to myCustomControl - I keep getting "invalid cast" exceptions. Can anyone please explain what I'm doing wrong? Thanks Charlie