Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cast ObjectHandle to UserControl

How to cast a Remoting.ObjectHandle to UserControl type ?

I would like to dynamically instanciate a UserControl :

UserControl myUserControl = (UserControl)Activator.CreateInstance(Assembly.GetExecutingAssembly().FullName, "Client.IndexView");

Error : Cannot cast expression of type 'System.Runtime.Remoting.ObjectHandle' to 'UserControl'

like image 1000
Steven Muhr Avatar asked Sep 03 '25 03:09

Steven Muhr


1 Answers

What if you use the Unwrap method:

var instance = Activator.CreateInstance(Assembly.GetExecutingAssembly().FullName, "Client.IndexView");
UserControl myUserControl = (UserControl)instance.Unwrap();
like image 86
misha Avatar answered Sep 05 '25 17:09

misha