Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2004

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hazz - 15 Jun 2004 20:57 GMT
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(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:\\DBPassword\\DBPassword.dll");

Type[] types = assmbly.GetTypes();
foreach (Type t in types)
{
   mi = t.GetMethod("GetPassword");
   if (mi != null)
  {
        DBPassword ppdr =
(DBPassword)Activator.CreateInstance(t,BindingFlags.Public |
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
p.s.  I cross-posted with the remoting newsgroup as I wasn't sure which was
the best newsgroup for this question.
hazz - 15 Jun 2004 21:07 GMT
sorry, wrong newsgroup. meant c#.

> this is a repost with a hopefully more clearly stated scenario and more
> concise questions at the end.
[quoted text clipped - 73 lines]
> p.s.  I cross-posted with the remoting newsgroup as I wasn't sure which was
> the best newsgroup for this question.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.