473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

RE: activator classes n createInstance()

Found it.

string name = Properties.Settings.Default.ClassName.ToString();

//"myproject.myclass, myassembly" format.
//name = "ABC.MyClass, Assem" ;
Type t = Type.GetType(name);

Object obj = Activator.CreateInstance(t);
string result = t.InvokeMember("methodName",
System.Reflection.BindingFlags.InvokeMethod, null, obj, new object[] {
strA,
strB });

cheers

"Andrew" wrote:
Hi,

I've looked at the Activator classes and I've come out with these samples of
code. However there is an error:

e.g. codes:
=======
string name = "ClassABC";

Type theMathType = Type.GetType("System.Math");
Type testType = Type.GetType(name);
Type testType2 = Type.GetType("name");

--both testType and testType2 gives "null".

Object theObj2 = Activator.CreateInstance(theMathType); --Error: Cannot

create an abstract class.
Object theObj3 = Activator.CreateInstance(testType); --Error: Value
cannot be

null. Parameter name: type.
Object theObj4 = Activator.CreateInstance(testType2); --Error: Value
cannot be

null. Parameter name: type.

I'm not very familiar with CreateInstance method etc ...
I just want to create an instance of "name" which is the name of the class
that I want to instantiate.

Thanks

regards,
Andrew
Jun 27 '08 #1
0 1273

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Terry | last post by:
I'm building some dll assemblies that have in them the implementation of an abstract class defined in a different assembly. I'm trying to create objects of the type defined in the dlls with...
7
by: hazz | last post by:
this is a repost with more concise code (well, for me) and better questions (I hope....) . given the following two classes, my intent is to use either Activator.CreateInstance or InvokeMember pass...
3
by: Rob Richardson | last post by:
Greetings! I am trying to make it possible for new derived classes of an object to be used by my application without rebuilding the application. The new classes will be made known to my...
0
by: MichaelSL | last post by:
When I build an executable which uses System.Activator.CreateInstance and execute it on my PC, which has Microsoft Visual Studio installed, the CreateInstance works just fine and the class...
1
by: hazz | last post by:
this is a repost with a hopefully more clearly stated scenario and more concise questions at the end. given the following two classes, my intent is to use pass a token into the instantiated class...
2
by: jcomber | last post by:
Hi, I'd be grateful for some help... I'm trying to create a late bound object using: Activator.CreateInstance(Type, ConstructorParameters()) The constructor of the object takes a delegate...
1
by: Johnny R | last post by:
Hello, I'm loading a Class from Assemly DLL using Activator.CreateInstance. That loaded Class is executed in a worker Thread with no loop. What actually happends when class is loaded using...
1
by: Dan Dorey | last post by:
My goal is to pass in an assembly and have the method return an instance of any classes that inherit from the generic type T. My problem is that I'm unable to cast from the result of...
0
by: Jon Skeet [C# MVP] | last post by:
On Apr 11, 8:40 am, Andrew <And...@discussions.microsoft.comwrote: Okay, that means you've either not given the full classname (including namespace) or it's not in mscorlib or the currently...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.