rbulph Posted December 21, 2007 Posted December 21, 2007 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? Quote
Erel Posted December 21, 2007 Posted December 21, 2007 Try: Activator.CreateInstance(GetType(X1), Reflection.BindingFlags.NonPublic OR Reflection.BindingFlags.Instance OR Reflection.BindingFlags.Static,... Quote
rbulph Posted December 21, 2007 Author Posted December 21, 2007 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." Quote
rbulph Posted December 21, 2007 Author Posted December 21, 2007 Got it. Just need to specify the argument for the culture parameter - Nothing will do. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.