473,770 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Activator.Creat eInstance or InvokeMember? Code is not getting me where I want to go.

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 DBPassword and return a string;
*************** *************** ********
public class DBPassword
{
public DBPassword()
{
//Empty constructor
}
public string GetPassword(Tok en token)
{
string sPassword = "Howdy Doody";
return sPassword;
}
}
*************** ***what I will pass into DB.GetPassword. GetPassword above
*************** *****
public class Token
{
protected string m_strPWD;
public Token()
{
}
public string Password
{
get
{
return m_strPWD;
}

set
{
m_strPWD=value;
}
}

*************** *************** ********

Token tkn = new Token();

tkn.Password = "password";

object[] args = {tkn}; //This is my intention, how do I do this?

Assembly assmbly = Assembly.LoadFr om("O:\\DBPassw ord\\DBPassword .dll");

Type[] types = assmbly.GetType s();
foreach (Type t in types)
{
mi = t.GetMethod("Ge tPassword");
if (mi != null)
{
DBPassword ppdr =
(DBPassword)Act ivator.CreateIn stance(t,Bindin gFlags.Public |
BindingFlags.In vokeMethod | BindingFlags.Cr eateInstance, null, args, null);
*************** *************** ********

When I run the above, "Constructo r on type DBPasswordProvi der.DBPassword not
found." } System.Exceptio n is thrown.

Why would this exception be thrown? There is a constructor for public
DBPassword.

Should I use Activator.Creat eInstance or InvokeMember?

How do I pass in the token as an arg if I do use CreateInstance?

Which of the 9 overloaded versions of Activator.Creat eInstance would I
choose for this?

Thank you very much,

-Greg
p.s. I cross-posted with the remoting newsgroup as I wasn't sure which was
the best newsgroup for this question.

Nov 17 '05 #1
1 4764
sorry, wrong newsgroup. meant c#.

"hazz" <ha**@sonic.net > wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
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 DBPassword and return a string;
*************** *************** ********
public class DBPassword
{
public DBPassword()
{
//Empty constructor
}
public string GetPassword(Tok en token)
{
string sPassword = "Howdy Doody";
return sPassword;
}
}
*************** ***what I will pass into DB.GetPassword. GetPassword above
*************** *****
public class Token
{
protected string m_strPWD;
public Token()
{
}
public string Password
{
get
{
return m_strPWD;
}

set
{
m_strPWD=value;
}
}

*************** *************** ********

Token tkn = new Token();

tkn.Password = "password";

object[] args = {tkn}; //This is my intention, how do I do this?

Assembly assmbly = Assembly.LoadFr om("O:\\DBPassw ord\\DBPassword .dll");

Type[] types = assmbly.GetType s();
foreach (Type t in types)
{
mi = t.GetMethod("Ge tPassword");
if (mi != null)
{
DBPassword ppdr =
(DBPassword)Act ivator.CreateIn stance(t,Bindin gFlags.Public |
BindingFlags.In vokeMethod | BindingFlags.Cr eateInstance, null, args, null); *************** *************** ********

When I run the above, "Constructo r on type DBPasswordProvi der.DBPassword not found." } System.Exceptio n is thrown.

Why would this exception be thrown? There is a constructor for public
DBPassword.

Should I use Activator.Creat eInstance or InvokeMember?

How do I pass in the token as an arg if I do use CreateInstance?

Which of the 9 overloaded versions of Activator.Creat eInstance would I
choose for this?

Thank you very much,

-Greg
p.s. I cross-posted with the remoting newsgroup as I wasn't sure which was the best newsgroup for this question.


Nov 17 '05 #2

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

Similar topics

2
505
by: shmeian | last post by:
I have the following code which works fine. However I want to pass the object I'm instantiating a string for its constructor. I can't get the syntax right. Can someone give me an example of Activator.CreateInstance where they pass an argument with the object type? Assembly a = Assembly.GetExecutingAssembly(); Type type = a.GetType("MyAssemb.MyClass"); Object o = Activator.CreateInstance(type); MyClass myObj=...
2
1636
by: Baskar RajaSekharan | last post by:
Hi I have one doubt in C#. I created one component called CustomTesting in VC7. The DLL contains Two Method called Execute and SetOCxInterface. I want to Load the Dll from my Sample application(which is in C#) with out Addeing it in Reference. ie i want to load it dynamically with the help of Activator.CreateInstance. Then i want to access those method. How to Do that?
2
4570
by: 2G | last post by:
Hi, I'm having some problems creating an instance of the dataset I compile in memory and I don't know why. I what to do this to Invoke WriteXmlSchema or GetSchemaSerializable so I could save the xsd of my dataset. The compiling seems to succeed since cr.Errors.HasErrors returns false; Anyone that knows what the problem could be?
7
12034
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 a token into the instantiated class DBPassword and return a string; ************************************** namespace DBPasswordProvider public class DBPassword {
3
17070
by: System.Reflection Activator | last post by:
************************************** //Load the Assembly Assembly a = Assembly.LoadFrom(sAssembly); //Get Types so we can Identify the Interface. Type mytypes = a.GetTypes(); BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly); //Iterate through the Assembly to find Class with a Public Interface.
2
1857
by: Huw | last post by:
I have written a small procedure that opens a dialog that I pass it. Sub MyOpen(txtForm as string) Dim frm As Object Dim frmType As Type frmType = Type.GetType(txtForm) frm = Activator.CreateInstance(frmType) frmType.InvokeMember("ShowDialog",
1
11538
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 Activator.CreateInstance? If I create same class using Activator.CreateInstance many times will there be multiple instances of that same class created by Activator.CreateInstance?
0
1434
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 executing assembly, in which case you need to give assembly details as well. The line with testType2 is explicitly trying to find a class called "name". The string "name" and the variable called name are completely independent things.
0
1297
by: =?Utf-8?B?QW5kcmV3?= | last post by:
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",
0
9432
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8891
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.