I am trying to get all assemblies in CurrentDomain using AppDomain.CurrentDomain.GetAssemblies() to write their FullName into a DropDownList, however if I don’t instantiate them, they are not seen in returned array from GetAssemblies() in CurrentDomain.
They are all added as Reference and in Reference folder of the solution. Only time I can get them from the GetAssemblies() is when I first instantiate them.
How to overcome this problem with an easy and more generic way instead of instantiate them everytime when I add new Assembly, etc.
Due to company policy, I have to obfuscate some parts of the images:

All the assembilies are referenced in Reference folder:

There is actually something subtle that happens here in addition to the other people’s comments.
VisualStudio actually does not add .dll references to the assembly manifest of your built assembly’s reflection info unless they are actually used.
As a sample, make a new project, and reference an assembly. I used
nunit.framework.dllas an example.But don’t actually use it. My code is simply:
But the Project does have a reference to NUnit in VisualStudio. Now build it, and open the assembly in
ildasm.exeand the top of the manifest is:Now, in the code, just use anything from NUnit:
Again rebuild and check the assembly manifest in
ildasm.exe:Note that now there is an extern in the IL. This also feeds reflection, so it knows what the dependent assemblies are to be loaded.
Past that little detail, as other have stated, the runtime doesn’t actually load an assembly until it is needed for the first time, hence your AppDomain doesn’t have the assemblies loaded until you instantiate or use something from that assembly.
That detail above comes into play when you start to try to use the
Assembly.GetReferencedAssemblies()method.So in VisualStudio, I have a project that has these references:
Then I have the C# code:
Note that I even have a
using NUnit.Framework;statement! But I don’t actually use NUnit anywhere, so it is not a referenced assembly. The output of running this is:That is it.
If I add this line into my test app:
Now something actually uses NUnit,a nd my console output is: