Skip to content

Consider using Assembly.Load instead of Assembly.LoadFrom #8

@KirillOsenkov

Description

@KirillOsenkov

Here:
https://github.com/Microsoft/MSBuildLocator/blob/master/src/MSBuildLocator/MSBuildLocator.cs#L75

consider using:

if (File.Exists(targetAssembly))
{
    var name = AssemblyName.GetAssemblyName(targetAssembly);
    Assembly.Load(name);
}

instead of Assembly.LoadFrom.

LoadFrom is not great because it loads into the LoadFrom context and has other repercussions. You almost always want to load assemblies using the trick above.

GetAssemblyName stashes the full path to the assembly in the _Codebase field:
http://referencesource.microsoft.com/#mscorlib/system/reflection/assemblyname.cs,45
It is then used as a hint to the loader to load it from that location.

cc @davkean

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions