Search code examples
.netvb.netreflectionnamespacesassembly-references

VB.NET determine project's imported namespaces at runtime


In VB.NET (or C#), how can I determine at runtime which namespaces are imported in the Project properties? I'll be using this for dynamic compilation, I'd like the dynamic code to automatically have the same Imports as its parent project.

I've seen "Finding all Namespaces in an assembly using Reflection (DotNET)" already. It and other examples I've found do not appear to solve my issue, as I've found they provide a list of all project references. Yes, I want all these to be accessible, but some through fully qualified names, rather than all Imported into the root namespace. And I want to select solely through the existing Project Properties' "Imported Namespaces" list, rather than maintaining a separate and redundant list in my dynamic execution class.


Solution

  • What you are describing is not possible with the compiled assembly, because its a compiler feature. After compilation there is only the information of the used types (what you can get via reflection), not how they were referenced in the source code.