3F / DllExport

.NET DllExport with .NET Core support (aka 3F/DllExport aka DllExport.bat)
MIT License
938 stars 131 forks source link

System.MissingMethodException in C#/EExternalException in Delphi when calling a C# exported function that calls another exported function #155

Closed meindratheal closed 4 years ago

meindratheal commented 4 years ago

Steps to reproduce:

  1. Create a new solution with two projects, a Class Library and something runnable (I've used both a console app and a forms application). I'm targeting .NET Framework 4.7.2. Can also reproduce if targeting 4.5.0.
  2. Install the NuGet package on the Class Library. When the DllExport configuration pops up, tick the Installed button on the Class Library project, then hit Apply. No other changes needed.
  3. Write two exported functions in the Class Library project. Have the second one call the first. So something like this:
        [DllExport]
        public static void WorksFine()
        {
            //Does nothing.
        }

        [DllExport]
        public static void CausesError()
        {
            WorksFine();
        }
  1. Call those functions from with C#. Observe that you get System.MissingMethodException when CausesError tries to call WorksFine.

    
    static void Main(string[] args)
    {
        Console.WriteLine("Calling WorksFine");
        Exports.WorksFine();
        Console.WriteLine("Calling CausesError");
        Exports.CausesError(); //Throws System.MissingMethodException: 'Method not found: 'Void TheDll.Exports.WorksFine()'.'
        Console.WriteLine("Done");
        Console.ReadKey();
    }

    In my use case I'm consuming these exports in a Delphi program. Calling WorksFine works fine, calling CausesError generates an EExternalException on the Delphi side, which indicates that an uncaught exception happened in the C# side (which would be the MissingMethodException). . . .

Demo Project files / Samples / etc.:

Minimal sample project attached. DllExportBug.zip

meindratheal commented 4 years ago

Edited title and body to include that this also happens if everything's purely in C#, rather than calling from Delphi.

3F commented 4 years ago

@meindratheal Is there any reason why are you avoiding our bug issue template ? Please update information.

It can be a duplicate of #130

meindratheal commented 4 years ago

That would be because I didn't know that template existed! I've updated to match, and also attached a minimal repro.

3F commented 4 years ago

Thanks for the updated information! This is duplicate of #94