C#DLL导出到Inno-Setup - 错误E0434F4D

时间:2014-12-31 10:31:13

标签: c# inno-setup dllexport

我有一个C#DLL,我通过RGiesecke.DllExport从中导出一个方法。

当我从C#控制台应用程序调用导出的方法时,一切正常 但我在 Inno-Setup 中使用它我得到以下错误

enter image description here

Exported方法使用另一个DLL中的另一个方法。 对我来说很奇怪,为什么我可以从另一个类调用一个方法,而不是从另一个DLL调用。 在下面的示例中,我标记了无法正常工作的方法。

我的问题是,为什么我会收到此错误?

第一个DLL

namespace ExposeTestLibrary
{
    public class TestClass
    {
        [DllExport("Test2", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
        public static void Test2()
        {
            //works
            TestClass tc = new TestClass();
            tc.DoSomething2();

            //works
            SubLib2 sl2 = new SubLib2();
            sl2.DoSomething3();

            //Doesn't work
            SubLib sl = new SubLib();
            sl.DoSomething();
        }

        public void DoSomething2() 
        {
            System.Windows.Forms.MessageBox.Show("DoSomething2");
        }
    }

    public class SubLib2
    {
        public SubLib2()
        {

        }

        public void DoSomething3()
        {
            System.Windows.Forms.MessageBox.Show("DoSomething3");
        }
    }
}

第二个DLL

namespace ExposeSubLibrary
{
    public class SubLib
    {
        public SubLib() 
        {

        }

        public void DoSomething() 
        {
            System.Windows.Forms.MessageBox.Show("DoSomething");
        }
    }
}

以下是我从 Inno-Setup

中调用它的方法
[Code]
    procedure Test2();
    external 'Test2@{src}\ExposeTestLibrary.dll stdcall loadwithalteredsearchpath';

function InitializeSetup:boolean;
begin
    MsgBox('WAIT', mbInformation, MB_OK); 
    Test2();
    result:=true;
end;

1 个答案:

答案 0 :(得分:2)

汉斯是对的,你必须考虑如何报告或记录错误。

但是,在你的情况下,我猜问题是CLR找不到其他程序集。 程序集不是相对于使用它们的程序集解析的,而是解析当前appdomain的探测路径。 在您的情况下,appdomain将是默认的,您的探测路径将是可执行文件的目录。

您可以在TestClass的静态ctor中为AssemblyResolve设置处理程序。或者只是用它的完整文件名(也在静态ctor中)装配一次。