3F / DllExport

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

External Exception E0434352 using .NET Core #239

Open engycz opened 4 days ago

engycz commented 4 days ago

I have a simple project in .NET Core 8.0 and a simple test project in C++.

DLLCoreExportsDemo.zip

I have two simple exported functions

using System;
using System.Runtime.InteropServices;

namespace ExportsDemo
{
    public static class Exports
    {
        [DllExport(CallingConvention.StdCall)]
        public static Int32 DemoProc1()
        {
            return 1337;
        }

        [DllExport(CallingConvention.StdCall)]
        public static Int32 DemoProc2()
        {
            DateTime t = DateTime.Now;
            return 1338;
        }
    }
}

First function DemoProc1 is working, the second DemoProc2 is failing with the exception 0xE0434352.

#include <iostream>
#include <windows.h>

typedef int32_t(__stdcall* tDemoProc)();

int main()
{
    HINSTANCE hGetProcIDDLL = LoadLibraryA("ExportsDemo.dll");
    if (!hGetProcIDDLL) {
        std::cout << "could not load the dynamic library" << std::endl;
        return EXIT_FAILURE;
    }

    // resolve function address here
    tDemoProc DemoProc1 = (tDemoProc)GetProcAddress(hGetProcIDDLL, "DemoProc1");
    if (!DemoProc1) {
        std::cout << "could not locate the function" << std::endl;
        return EXIT_FAILURE;
    }

    tDemoProc DemoProc2 = (tDemoProc)GetProcAddress(hGetProcIDDLL, "DemoProc2");
    if (!DemoProc2) {
        std::cout << "could not locate the function" << std::endl;
        return EXIT_FAILURE;
    }

    // OK
    std::cout << DemoProc1() << std::endl;

    // Exception
    std::cout << DemoProc2() << std::endl;
}
Unhandled exception at 0x00007FF839C1B699 (KernelBase.dll) in UseDemo.exe: 0xE0434352 (parameters: 0xFFFFFFFF80070002, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FF81C9F0000).

Running on console

Unhandled exception: System.IO.FileNotFoundException: Could not load file or assembly System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a or one of its dependencies. The system cannot find the file specified.

Both projects are configured as x64.

I have Use our IL Assembler and Rebase System Object: System.Runtime -> mscorlib enabled.

obrazek

C:\>dotnet --list-runtimes

Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Demo Project: DLLCoreExportsDemo.zip

3F commented 1 day ago

Hello Jiří,

Thank you for the detailed report! I apologize for the inconvenience. Although modern .NET 8 is not supported yet (I implemented the Rebasing only for System object that's not enough for modern versions), I already started review the DllExport project this month as it was mentioned earlier on https://mastodon.social/@github3F

So I'm currently working on fixing the DllExport's bugs and supporting the new modern platforms for it. Step by step; I need to fix the most important things first and then continue such the Rebasing feature.

That is, something in progress but I won't talk about any deadlines, ETA, and so on, because unfortunatelly I'm not in a position to plan anything even a week in advance.

Normally it might be December, but I've been outside the norm for too long, so...

3F commented 1 day ago

Side note to anyone who asks me about something on YouTube (because I get something also there from time to time):

Since Google continues to keep ~shadow block on my account (tf is going I don't know, but this 7+ years as far as I remember it), let me remind once again that not all of my comments may be published due to ...who knows the reason, and this cannot be controlled in any way in the admin panel. For example:

youtube-reply

Therefore, don't wast your time on youtube; contact me here or mastodon or email see in profile or in source code, I don't know but ...