C# How light is Assembly.ReflectionOnlyLoad

495 Views Asked by At

I have a number of assemblies which I treat as libraries in my Unity game. When the game starts, I want to quickly read just the manifest of all files - there may be some 50+ at some point in the future - and make a list in memory.

I have packed some useful info in the copyright and product information fields which are sufficient to read, but I certainly do not want to load the whole assembly into my app domain or any other app domain.

AssemblyName.GetAssemblyName seems to be the most light weight

AssemblyName myAssemblyName = AssemblyName.GetAssemblyName("E:/Code/Projects/MyUtilities/bin/Debug/MyUtilities.dll");

But does not help as it only gives the assembly name, version and culture info. These cannot have custom strings anyway(the assembly fails to compile if I force some custom strings in there using the code in AssemblyInfo.cs)

So that brings me to the last option which is Assembly.ReflectionOnlyLoadFrom

Assembly myAssembly = Assembly.ReflectionOnlyLoadFrom("E:/Code/Projects/MyUtilities/bin/Debug/MyUtilities.dll");

object[] map = myAssembly.GetCustomAttributes(false);

Does this actually load the whole file? That would be too much for me as I only want the attributes.

If it does then I am left with no options but to prepend some extra bytes to the assembly file myself and remove the bytes before I hand the byte array to

Assembly.Load(bytes);
0

There are 0 best solutions below