[Python] Why does my pythonnet not load the correct dependency when loading DLL:s via...

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm writing a Python application that uses clr 3.0.3.

    I'm trying to load a DLL using System.Reflection.Assembly.LoadFrom. My code is basically doing the following:

    def load_from(dll_paths):
    for dll_path in dll_paths:
    print(dll_path)
    assembly = System.Reflection.Assembly.LoadFrom(dll_path)
    print("")
    for referenced in assembly.GetReferencedAssemblies():
    print(f" {referenced}")
    print("")
    for loaded_assembly in System.AppDomain.CurrentDomain.GetAssemblies():
    print(f" {loaded_assembly}")
    print("")


    The result is something like this: [​IMG]:

    The assemblies I'm trying to load have the following directory structure:

    [​IMG]

    Assembly.DLL Version 1 and Assembly.DLL Version 2 have the same name and public key but differing version numbers. When loading Assembly.DLL version 1 it properly locates and loads Dependency Version 1 but when I load Assembly.DLL version 2 it never loads Dependency Version 2

    My questions is why Dependency 2 is never loaded? If the CLR can't locate Dependency 2 when running LoadFrom, why doesn't it throw an exception? When running code in Assembly 2 it attempts to reference stuff in Dependency 1 which produces an exception at runtime since they are incompatible.

    Continue reading...

Compartilhe esta Página