I have a dll that I am trying to create an instance of but is saying the protection level is high. I've read that I can use reflection to create this instance. Anyone know the proper syntax for doing this?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Oct 30, 2014, 9:54 AM
First create this simple dll, marc_test.dll :
// marc_test.cs
Now create the following executable which loads the dll at runtime (place the dll in the same folder as the executable to facilitate this):
The output,as expected, is:
Notice a couple of points here:
1. Although MyClass2 is internal to the dll, we are still able to create an instance of it.
2. Also, even though MyClass2.MyMethod2 is an internal method, we can still call it just by changing the BindingFlags variable to include BindingFlags.NonPublic rather than BindingFlags.Public.