Search code examples
c#inno-setupdllexport

C# DLL Export to Inno-Setup - Error E0434F4D


I have a C# DLL from which I export a method via RGiesecke.DllExport.

When I call the exported method from a C# Console Application everything works fine but i use it in an Inno-Setup and there i get the following error:

enter image description here

The Exported method uses another Method from another DLL. Strange to me is why i can call a Method from another Class but not from another DLL. In the Sample below i marked the method that doesn't work.

My question is, why do i get this error ?

First 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");
        }
    }
}

Second DLL

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

        }

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

And here is how i call it from 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;

Solution

  • Hans is right, you have to think about how to report or log errors.

    However, in your case I guess the problem is that the CLR cannot find the other assembly. Assemblies are not resolved relative to the assembly that is using them but to the probing path of the current appdomain. In your case the appdomain will be the default one and your probing path will be the directory of the executable.

    You can setup a handler for AssemblyResolve in the static ctor of TestClass. Or just assembly.load it once with its full filename (also in the static ctor).