correct overloaded version for Activator.CreateInstance? I am getting "Constructor on type xxx not f

H

hazz

Is Activator.CreateInstance(t,BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.CreateInstance, null, args, null) appropriate given the following;

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

public interface IPasswordProvider
{
string GetPassword(Token token);
}

public DBPassword()
{
// constructor logic goes here
}

**************************************
public string GetPassword(Token token)
{
string sPassword;
sPassword = "password";
return sPassword;
}

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

and what I have to include as an argument to pass to the GetPassword() is an instance of the following class;

public class Token
{
protected string m_strPWD;
public Token()
{
}
public string Password
{
get
{
return m_strPWD;
}

set
{
m_strPWD=value;
}
}

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

for which I am attempting something like;

Token tkn = new Token();

tkn.Password = "password";

object[] args = {tkn };

but when I utilize this along with Activator.CreateInstance(t,BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.CreateInstance, null, args, null),

I get the following - {"Constructor on type DBPasswordProvider.IPasswordProvider not found." } System.Exception

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

Any help will be very much appreciated...

Thank you,

-Greg
 
M

Mattias Sjögren

but when I utilize this along with Activator.CreateInstance(t,BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.CreateInstance, null, args, null),

I get the following - {"Constructor on type DBPasswordProvider.IPasswordProvider not found." } System.Exception

Which type does the t variable represent here? If it's
typeof(IPasswordProvider) then the error message makes sense, since
interfaces don't have constructors.



Mattias
 
H

Hazzard

Thank you Mattias! As a follow up to that is it necessary to take the
interface out of the assembly?
Appreciatively,
-Greg

Activator.CreateInstance(t,BindingFlags.Public | BindingFlags.InvokeMethod |
BindingFlags.CreateInstance, null, args, null),DBPasswordProvider.IPasswordProvider not found." } System.Exception
 
H

hazz

I removed the interface from the assembly and the reference to the interface
and still get the same error.
I am thinking that this is a generic error message and that the real problem
is that one of the arguments I am passing is not correct. Like the args for
example. I am trying to pass in my token object and it may not like
that....
Thanks you for any comments or ideas.
-Greg

Activator.CreateInstance(t,BindingFlags.Public | BindingFlags.InvokeMethod |
BindingFlags.CreateInstance, null, args, null),DBPasswordProvider.IPasswordProvider not found." } System.Exception
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top