Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: method 'is inaccessible due to its protection level'

$
0
0
Hi Ron,

Is there a reason why the property is accessible and the method is not?

Yes, it has to do with the way ClearScript binds to .NET type members. For most things it uses reflection, but for methods it uses the C# runtime binder. These facilities have different rules for accessing non-public resources.

Try using ScriptEngine.AccessContext. For example:
engine.AccessContext = typeof(Program);
From the ClearScript Library Reference: "By setting this property to a type you declare that script code running in the current script engine is to be treated as if it were part of that type's implementation. Doing so does not expose any host resources to script code, but it affects which host resources are importable and which members of exposed resources are accessible."

Hopefully this solution is practical in your actual scenario.

Good luck!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>