1

I'm running:

  • python 3.7.9 (64-bit)
  • pythonnet 2.4.0

... and I have the following problem: I have a bunch of DLL:s, all of which implement the same interface. I want to load them, run some code and then unload them. Is it possible to "reload" a DLL using pythonnet? Do I need to reload the module as well?

def iterate_dlls():
    dll_paths = [
        'DLLLocation1\\DLLName.dll',
        'DLLLocation2\\DLLName.dll',
    ]

    for dll_path in dll_paths:
        dir_path, dll_name = os.path.split(dll_path)
        sys.path.append(dir_path)
        clr.AddReference("AssemblyName")

        import AssemblyName

        # Usage of assembly

        sys.path.remove(dir_path)

        #
        # ? What else is needed to completely unload the DLL here?
        #
Anton Lahti
  • 410
  • 3
  • 10
  • One approach might be to [restart python script](https://stackoverflow.com/a/66428918/199364). That isn't python.net example, but I believe it should work. – ToolmakerSteve Jan 07 '22 at 01:19

0 Answers0