Saving the assembly as an array of bytes suitable for Assembly.Load

I noticed that Assembly.LoadFrom has the following overload

public static Assembly Load(
    byte[] rawAssembly
)

How to save an assembly as an array of bytes to create it like this?

Context: I want to write a test harness that will provide backward compatibility of the service. I want to load the finished versions of the client into my wiring and call the service from different versions. I think storing old versions as a byte [] would allow me to freeze them.

+3
source share
2 answers

If you have old versions in the form of files (just as they were created), all you need. You can read them into an array of bytes (e.g. using File.ReadAllBytes) if you need to.

, .

+5

:

byte[] assemblyBytes = File.ReadAllByes(assemblyPath);

, .

+1

All Articles