How to get assembly?
I'm trying to get assembly using this:
var test = AppDomain.CurrentDomain.GetAssemblies();
I don't understand why but I don't see my assembly in test but my project has reference to this assembly14 Replies
Are you saying to have an assembly
A
which is referenced by the running project B
but A
isn't in test
?
Assemblies aren't loaded into the domain until they're needed.
You can test this by using a data type in your Program.cs
from A
in B
, then test
should contain A
.@ivefifthsence There is an extension on
Assembly
called GetReferencedAssemblies()
What are you trying to actually do?
Remember, assemblies only get loaded when they are used.
all I need is pass a name of assembly and then try to find all needed types
Are you able to find any assemblies?
I don't understand why but I can find
ResourceManager.Commands
but not Operational.ReadModel.Commands
both were referenced in csprojAre you using anything from
Operational.ReadModel.Commands
in your code?
It can be anything, just a piece of code.hm
I understand
Just by giving a project a reference, it doesn't mean it will get loaded. It will only load if, you are using it.
yes I see, thanks
I will use
foreach(var assembly in assemblyNames.Select(Assembly.Load))
instead
why do you think about it?I get the idea of what you are trying to do. You are technically using code from
Operational.ReadModel.Commands
but not directly and that's why the assembly is not getting loaded.yes
You can maybe improve the code, by only loading your own assemblies.