H
hazz
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
{
public DBPassword()
{
//Empty constructor
}
public string GetPassword(Token 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.LoadFrom("O:\\DBPasswordProvider\\bin\\Debug\\DBPasswordProvider.dl
l");
Type[] types = assmbly.GetTypes();
foreach (Type t in types)
{
mi = t.GetMethod("GetPassword");
if (mi != null)
{
string typeName = t.FullName;
{
DBPasswordProvider.DBPassword ppdr =
(DBPasswordProvider.DBPassword)Activator.CreateInstance(t,BindingFlags.Publi
c | BindingFlags.InvokeMethod | BindingFlags.CreateInstance, null, args,
null);
**************************************
When I run the above, "Constructor on type DBPasswordProvider.DBPassword not
found." } System.Exception is thrown.
Why would this exception be thrown? There is a constructor for public
DBPassword.
Should I use Activator.CreateInstance 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.CreateInstance would I
choose for this?
Thank you very much,
-Greg
(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
{
public DBPassword()
{
//Empty constructor
}
public string GetPassword(Token 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.LoadFrom("O:\\DBPasswordProvider\\bin\\Debug\\DBPasswordProvider.dl
l");
Type[] types = assmbly.GetTypes();
foreach (Type t in types)
{
mi = t.GetMethod("GetPassword");
if (mi != null)
{
string typeName = t.FullName;
{
DBPasswordProvider.DBPassword ppdr =
(DBPasswordProvider.DBPassword)Activator.CreateInstance(t,BindingFlags.Publi
c | BindingFlags.InvokeMethod | BindingFlags.CreateInstance, null, args,
null);
**************************************
When I run the above, "Constructor on type DBPasswordProvider.DBPassword not
found." } System.Exception is thrown.
Why would this exception be thrown? There is a constructor for public
DBPassword.
Should I use Activator.CreateInstance 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.CreateInstance would I
choose for this?
Thank you very much,
-Greg