Skip to content

assemblymanager.cs: ResolveHandler finds assemblies based on StartsWith #533

Closed
@rmadsen-ks

Description

@rmadsen-ks

Environment

  • Pythonnet version: All
  • Python version: All
  • Operating System: All

Details

  • Describe what you were trying to get done.
    Loading an assembly called MyAssembly. Assembly did not exist, should have resulted in an error, but instead it loaded MyAssemblyTest.
    This can be done using Assembly.Load("AssemblyName").

Effectively this changes the way .NET normally loads assemblies and it ignores things such as strong naming. This could cause all kinds of unexpected effects in larger systems.

 static Assembly ResolveHandler(Object ob, ResolveEventArgs args){
            string name = args.Name.ToLower();
            for (int i = 0; i < assemblies.Count; i++) {
                Assembly a = (Assembly)assemblies[i];
                string full = a.FullName.ToLower();
                if (full.StartsWith(name)) { // this is a problem!
                    return a;
                }
            }
            return LoadAssemblyPath(args.Name);
        }

The FindAssembly method has obvious issues as well, but it only searches inside the python path, so the effect there is limited. The ResolveHandler searches through all currently loaded assemblies, which is a bigger problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions