ActiveX 程序集 ReflectionTypeLoadException

ActiveX Assembly ReflectionTypeLoadException

我创建了一个 activeX exe(已在 regasm.exe 注册),它加载了一个带有

的 DLL
Dim a As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile(FullPath)

此 DLL 使用接口“PSInterface”。作为普通的 exe,它可以工作,但是当我调用那个 activex 对象时,我在 a.GetTypes 中得到一个 ReflectionTypeLoadException。当我查看该错误时,我得到以下信息:

Could not load file or assembly 'PSInterface, Version=1.0.0.0, Culture = neutral, PublicKeyToken=null' or one of its dependencies. The System cannot find the file specified.

PSInterface.dll 与 exe 和 dll 在同一个文件夹中。

我能做什么?

为了从同一文件夹加载程序集,我设置了 AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf LoadFromSameFolder 和函数

Private Shared Function LoadFromSameFolder(ByVal sender As Object, ByVal args As ResolveEventArgs) As Assembly
        Dim folderPath As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location)
        Dim assemblyPath As String = Path.Combine(folderPath, New AssemblyName(args.Name).Name & ".dll")
        If Not IO.File.Exists(assemblyPath) Then
            assemblyPath = Path.Combine(folderPath, New AssemblyName(args.Name).Name & ".exe")
            If Not IO.File.Exists(assemblyPath) Then
                Return Nothing
            End If
        End If
        Dim assembly As Assembly = Assembly.LoadFrom(assemblyPath)
        Return assembly
    End Function

感谢@Craig 的帮助。

这里有更多内容:How to add folder to assembly search path at runtime in .NET?