Reading Assembly Info Without Loading It In C#

Guillaume Blanchet
Angular and dot NET
2 min readMar 26, 2019

--

I was puzzled by a very peculiar problem the other day: I wanted to read the manifest information from an assembly (dll). In C#, this is pretty straigthforward:

var assembly = Assembly.Load(“your-library.dll”);

Unfortunatly, this method load the assembly in RAM. So if you want to read the same assembly both in 64 bits and 32 bits in the same program you’ll end up with a pretty bad runtime error. Same thing if you want to read multiple assemblies build for multiple processor architectures different from your main program… Why would you do that? Well, as part of a DevOps process, you could read assemblies information (dependencies, processor architecture, version, .NET framework, etc.) generated by a build server and store them in a well structured hierarchy like:

C:\packages\your-library\4.0\net451\x64\your-library.dll

as a Nuget local feed requires for example… These librairies could then be imported correctly in you other projects by a package manager.

There is a pretty powerful technology to solve this kind of problem (and much much more) called “decompiler”. The idea is to reference libraries from a good decompiler in your code and use them to read the info of your assemblies without loading it. The example below use DnSpy librairies available here:

Reading assembly info without loading the dll in RAM

--

--

Guillaume Blanchet
Angular and dot NET

Currently working with Viagénie inc. in Quebec. Interested in devops, operation research and software development. c.v.: https://gblanchet.azurewebsites.net/