System.MissingMethodException when calling Private constructor

  • Thread starter Thread starter Rob Blackmore
  • Start date Start date
R

Rob Blackmore

Hi,

Can anyone advise how to call a private constructor using reflection? I
currently get the above error which is rectified by changing the New() to
Public from Friend but I ideally wish to leave it as Friend to prevent it
being created outside of this project.

Thanks in advance

Rob
 
I mean calling a Friend constructor from another class within the same
project via reflection. Apologies for any confusion with the original post.
 
hi Rob,

Might help if you show the code you are using. If the type is in the same
assembly, then Activator.CreateInstance(GetType(foo), true) will work
 
Hi,

I am using GetType.InvokeMember with the invokeAttr argument of
Reflection.BindingFlags.CreateInstance and both classes are in the same VB
2008 project.

It works fine if I change the New() to Public but not whilst it is friend

Thank you

Rob
 
Hi Rob,

As I suggested earlier, you should use Activator.CreateInstance(type,True).
InvokeMember ignores other flags if the CreateInstance flag is specified.
 
Back
Top