problem with System.Activator.CreateInstance
.net, c#
Solution
Try `unwrap` after you call the `CreateInstance`, i.e.:
Object DataInstance = System.Activator.CreateInstance(System.Reflection.Assembly.GetExecutingAssembly().FullName,
"CMS.DataAccess.SQLWebSite").Unwrap();
IWebSite NewWebPage = (IWebSite)DataInstance;
Problem
I'm trying to use System.Activator.CreatInstance to Create an object based on the typeName. I'm using the following code: ``` Object DataInstance = System.Activator.CreateInstance( System.Reflection.Assembly.GetExecutingAssembly().FullName, "CMS.DataAccess.SQLWebSite"); IWebSite NewWebPage = (IWebSite)DataInstance; ``` `SQLWebSite` implements `IWebSite`. But, I get the following error: "Unable to cast object of type 'System.Runtime.Remoting.ObjectHandle' to type 'CMS.DataAccess.IWebSite'." Any ideas where I am going wrong?