c# - How to use reflection to find which namespaces are referenced by a class library? -


For example ...

  using the system; Using System.IO; Namespace, which is compiled in {class class] SomeClass {}}   

If this class library is mylibrary.dll , then I use the reflection to load I want to be able to Mylibrary.dll and find out if it is referencing System.IO namespace.

I have tried to use the Assembly.GetReferencedAssemblies and then identify namespaces in those assemblies, but it will always provide all the namespaces defined in those assemblies, even if they Are referred to in mylibrary.dll or not. System IO shares an assembly with system and many other important namespaces, this will not work.

Another thing I have thought to know is that a square is referenced from that name space, but I can not find any way to use the reflection.

This is a plugin for the system, and it is used by the plugin as some namespace, such as System.IO , if those namespaces are referenced, by loading the library Refuse

You can load assemblies in it, it will allow you to read the actual MSIL in each event.

Some of these will refer to the overload classes: call / callvirt / newobj and like each of these classes Read all the arguments for and you will be able to create a list of referenced types, which will take you to the list of namespaces.

But ...

Since you are trying to use it for safety, I must say that this is not a good idea: it is easy to bypass. For example, you can use the reflection, you can also block the reflection API, but then you can bypass it with compiled lambda quote, or P / Awake or mixed mode assembly ... you block them too But I do not think you will be able to stop it, every possible solution.

What you should do, load your assembly in one and allow CLR to reject the unsafe API call for you. This is a feature that was originally designed for that purpose. It has been implemented in CLR and it would be more secure to rely on it instead of its own solution.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -