Alternatively you could call 1. Get the Type by calling Type.GetType()
2. Call the GetConstructor() or GetConstructors() methods 3. Call Invoke on the returned ConstructorInfo object Later, Fred -----Original Message----- From: Jekke Bladt [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 27, 2004 12:54 PM To: [EMAIL PROTECTED] Subject: **SPAM** Re: [ADVANCED-DOTNET] Instance from type name. Just a quick follow-up that may elaborate more fully for the archives: AppDomain.CreateInstance returns a System.Remoting.ObjectHandle. In order to get at the object created, you need to use CreateInstanceAndUnwrap. Here is the code I wrote that uses it: public static IGroupOneSetting GetSetting(XmlNode settingNode) { string typeName = settingNode.Attributes["type"].Value; string typeAssembly; if(settingNode.Attributes["assembly"] == null) { typeAssembly = "GroupOne.Goat.Comet"; } else { typeAssembly = settingNode.Attributes["assembly"].Value; } AppDomain thisDomain = AppDomain.CurrentDomain; object theSettingObject = thisDomain.CreateInstanceAndUnwrap(typeAssembly, typeName); IGroupOneSetting theSetting = (IGroupOneSetting)theSettingObject; theSetting.Deserialize(settingNode); return theSetting; } Hopefully, this will save someone some time in the future. --Jekke -----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Palmer Fred Sent: Wednesday, October 27, 2004 11:36 AM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Instance from type name. AppDomain.CreateInstance() -----Original Message----- From: Jekke Bladt [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 27, 2004 10:32 AM To: [EMAIL PROTECTED] Subject: **SPAM** [ADVANCED-DOTNET] Instance from type name. All-- I'm sure I've seen this somewhere before, but can't find it now. If I have the name of a type as a string (ie "System.Text.StringBuilder," how do I use it to construct an instance of that type? TIA --Jekke =================================== This list is hosted by DevelopMentor(r) http://www.develop.com Some .NET courses you may be interested in: Essential .NET: building applications and components with C# November 29 - December 3, in Los Angeles http://www.develop.com/courses/edotnet View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor(r) http://www.develop.com Some .NET courses you may be interested in: Essential .NET: building applications and components with C# November 29 - December 3, in Los Angeles http://www.develop.com/courses/edotnet View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor(r) http://www.develop.com Some .NET courses you may be interested in: Essential .NET: building applications and components with C# November 29 - December 3, in Los Angeles http://www.develop.com/courses/edotnet View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor� http://www.develop.com Some .NET courses you may be interested in: Essential .NET: building applications and components with C# November 29 - December 3, in Los Angeles http://www.develop.com/courses/edotnet View archives and manage your subscription(s) at http://discuss.develop.com
