Krzysztof Sałajczyk
Krzysztof Sałajczyk

Reputation: 119

Prevent from using system.reflection in code

I wrote some code that compile in runtime C# code into assembly and stores it in memory in asp.net. After that it is possible to execute such compiled code.

Code to compile in runtime is written by user. It is always one class that inherits from base class I created. The problem is that user may have access to private fields and methods in this base class using reflection. So my question: is there a way to prevent using reflection?

Upvotes: 2

Views: 1250

Answers (1)

Yiğit Yener
Yiğit Yener

Reputation: 5986

There is ReflectionPermission attribute in Framework Class Library which controls access to non-public types and members through the System.Reflection APIs. If you can apply this attribute to your generated assembly in your case, you can try to see if it works.

Upvotes: 3

Related Questions