jborean93/PowerShell-ALC

How Did You Find The Documentation on `AddAssemblyInfo` `Dictionary`

Closed this issue · 4 comments

Great project. This is really helpful to understand. All the README.md's are really nice for someone as green as me.

I was curious. How did you come up with this object in the add method? I assume adding this data to the object allows the runtime to resolve the correct assembly?

public static void AddAssemblyInfo(Type type, Dictionary<string, object> data)
{
Assembly asm = type.Assembly;
data["Assembly"] = new Dictionary<string, object?>()
{
{ "Name", asm.GetName().FullName },
#if NET5_0_OR_GREATER
{ "ALC", AssemblyLoadContext.GetLoadContext(asm)?.Name },
#endif
{ "Location", asm.Location }
};
}

I read the below MS docs.

https://learn.microsoft.com/en-us/dotnet/core/dependency-loading/understanding-assemblyloadcontext
https://learn.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=net-8.0

This is just a custom method that just adds the key Assembly to the provided dictionary so it get's serialized for the JSON output. There is nothing too specific to the ALC side just that it gets the following details

  • Name - The same of the assembly the type provided is loaded in
  • ALC - The name of the ALC the type is loaded in (if it was in an ALC)
  • Location - The location of the DLL of the assembly the type is loaded in

Is there something specific that you wanted clarification on?

Oh that helps. I thought it was some requirement for the runtime to be able to know which ALC to use or something. Not sure if that makes sense. So it is strictly for output and demo purposes?

Yep, the runtime type lookup works like normal in the ALC the assembly was loaded in. This particular function is for demo purposes to show that the JSON library was loaded in an ALC.

Gotcha; makes sense. Thanks. :-)