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



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

for example...

using system; using system.io; namespace whatever { public class someclass { } }

if compiled class library mylibrary.dll, want able utilize reflection load mylibrary.dll , find out if referencing system.io namespace.

i've tried using assembly.getreferencedassemblies , identifying namespaces in assemblies, give me of namespaces defined in assemblies whether or not they're referenced in mylibrary.dll. since system.io shares assembly system , many other of import namespaces, won't work.

another thing i've thought of find out if class namespace referenced, can't find way using reflection.

this plugin system, , thought prevent plugin using namespaces, such system.io, refusing load library if namespaces referenced.

you can load assembly in mono.cecil. allow read actual msil opcodes in each function.

some of these opcodes reference classes: call/callvirt/newobj , like. read arguments each of these classes , you'll able create list of referenced types, in turn lead list of namespaces.

but...

since you're trying o utilize security must it's not idea: easy bypass. instance utilize reflection. block reflection apis too, bypass compiled lambda expressions, or p/invoke, or mixed mode assembly... block them don't think you'll able prevent every possible workaround.

what should do, load assembly sandboxed appdomain , allow clr reject insecure api calls you. feature designed purpose. it's implemented in clr , it'll much safer rely on instead of own solution.

c# .net reflection namespaces

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -