Why does Assembly.GetTypes() require references?

后端 未结 4 1973
[愿得一人]
[愿得一人] 2021-01-12 16:34

I want to get all of the types from my assembly, but I don\'t have the references, nor do I care about them. What does finding the interface types have to do with the refere

4条回答
  •  日久生厌
    2021-01-12 16:59

    Loading an assembly requires all of its dependencies to be loaded as well, since code from the assembly can be executed after it's loaded (it doesn't matter that you don't actually run anything but only reflect on it).

    To load an assembly for the express purpose of reflecting on it, you need to load it into the reflection-only context with e.g. ReflectionOnlyLoadFrom. This does not require loading any referenced assemblies as well, but then you can't run code and reflection becomes a bit more awkward than what you 're used to at times.

提交回复
热议问题