Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'd like to use Activator.CreateInstance with a non-public constructor for a class of mine. Here's my code:

 

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


       Activator.CreateInstance(GetType(X1), Reflection.BindingFlags.NonPublic, Nothing, New Object() {8})

       Dim j As New X1(8)
   End Sub
End Class
Public Class X1
   Friend Sub New(ByVal p As Long)
       MsgBox(p)
   End Sub
End Class

 

but in spite of the use of the NonPublivc flag, I get the message that the constructor is not found. Maybe I need to set the binder parameter to something, but I've no idea what. Anyone know how to go about this?

Posted

Try:

Activator.CreateInstance(GetType(X1), Reflection.BindingFlags.NonPublic OR Reflection.BindingFlags.Instance OR Reflection.BindingFlags.Static,...

Posted
Try:

Activator.CreateInstance(GetType(X1), Reflection.BindingFlags.NonPublic OR Reflection.BindingFlags.Instance OR Reflection.BindingFlags.Static,...

 

I still get the error "Constructor on type 'WindowsApplication1.x1' not found."

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...