Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External Exception E0434352 using .NET Core #239

Closed
engycz opened this issue Nov 21, 2024 · 3 comments
Closed

External Exception E0434352 using .NET Core #239

engycz opened this issue Nov 21, 2024 · 3 comments

Comments

@engycz
Copy link

engycz commented Nov 21, 2024

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]
  • DllExport -version: v1.7.4.29858+c1cc52f
  • Used Visual Studio 2022 Version 17.12.1

Demo Project:
DLLCoreExportsDemo.zip

@engycz engycz added the bug label Nov 21, 2024
@3F
Copy link
Owner

3F commented Nov 24, 2024

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
Copy link
Owner

3F commented Nov 24, 2024

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 ...

@3F
Copy link
Owner

3F commented Dec 4, 2024

I close the issue as duplicate of a common support for modern .NET, for example #219, in order to get a clean to-do list

Feel free to continue here or there

@3F 3F closed this as completed Dec 4, 2024
@3F 3F added this to the 1.8 milestone Dec 4, 2024
@3F 3F added duplicate and removed bug labels Dec 4, 2024
@3F 3F added the netcore label Dec 17, 2024
3F added a commit that referenced this issue Feb 25, 2025
* NEW: Extends support for .NET 9, .NET 8, .NET 7,
       .NET 6, .NET 5, netcoreapp3.1, netstandard2.1, ...
       Issues: #219, #193, #132, #239

* NEW: Custom `.typref ...` & `.assembly extern ...` in the Wizard
       using modern 3F's IL Assembler 9.3+

* NEW: Support $-interpolation in modern .NET 9-6, Span, Memory, ...
       configure in the Wizard.

* NEW: New [Ref] packages control and related options.

* NEW: ImageBase + step control in multiple targeting.
       configure in the Wizard.

* NEW: New `DllExport -pe` keys:
          -list-addr, -list-ord, -list-all
          -magic, -num-functions, -base

* NEW: Official ILRepack support in Pre-processing; 2.0.39
       https://github.com/gluck/il-repack/releases/tag/2.0.39

* NEW: New PE Check option to control PE32/PE32+ arch.

* NEW: -action RecoverInit in addition to -action Recover;
       Recover to initial setup using predefined/exported data.

* NEW: Option to refresh intermediate module (obj) using modified. Issue #206.

* NEW: x86+x64 copy support for `Publish` targets. Related issue #224.
       `DllExportResolvePublish` property to control it.

* FIXED: Crashes or empty exports if code contains `.class extern forwarder` declarations.

* FIXED: error: syntax error at token '.' in .interfaceimpl type... Issue: #205.

* FIXED: Post-Proc: possible "The given key was not present in the dictionary."

* FIXED: Fixed Pre-Proc ILMerge for netcore.

* FIXED: Fix copying to own directory for "Provide x86+x64 assemblies"
         when no active dependencies.

* FIXED: Pre-Proc: fixed edit Exec raw command in the Wizard.

* FIXED: Fixed possible Incorrect RVA: 0 when PE Check is on.

* FIXED: Fixed -action Export: Parameter "unevaluatedValue" cannot be null.

* FIXED: Fixed Post-Proc DllExportDirX64 & DllExportDirX86 properties.

* FIXED: DllExportResolvePublish support for a single platform
         Related issue #235 or like.

* FIXED: Failed to write to log file ... because it is being used by another process. Issue #223.

* CHANGED: Execute `-action Restore` in case of loss of generated meta
         for the cases like ImplicitUsings=true etc.
         It will probably help with problems like #184.

* CHANGED: Improved support for nested projects using $(DllExportDir) etc.

* CHANGED: Improved managing `PlatformTarget` when applying the configuration.

* CHANGED: Improved TargetFrameworks multi-targeting support. ImageBase can be configured separately.

* CHANGED: Improved IsNetCoreBased logic for modern tfms.

* CHANGED: Improved cleaning logic at Pre-processing stage to delete correctly DllExport.Dll, Conari.dll
           and other assemblies from TargetDir when merging using [Ref] etc.

* CHANGED: `DllExport -action keys` are no longer case sensitive.

* CHANGED: Adds /PDB /OPTIMIZE and other types of PDB generation.
            Automatic option is relied on DebugType + Optimize + DebugSymbols properties:
            * Optimize: Optimize long instructions to short
            * PdbOptimize: +Create the PDB file without enabling debug info tracking
            * DebugOptimize: Enable JIT optimization, create PDB file, use implicit sequence points
            * Debug: Disable JIT optimization, create PDB file, use sequence points from PDB
            * DebugImpl: Disable JIT optimization, create PDB file, use implicit sequence points
            * Legacy True/False: Debug or Optimize

* CHANGED: Updated .PDB deletion logic according to ISymUnmanagedWriter problem.

* CHANGED: Use `wDxpMsgLevel` environment variable to control message level.

* CHANGED: Full integration with modern hMSBuild 2.4.1+
           https://github.com/3F/hMSBuild
           ```
           DllExport -hMSBuild -help
           ```

           GetNuTool now through hMSBuild engine:
           ```
           DllExport -hMSBuild -GetNuTool ...
           ```

* CHANGED: `DllExport -pe-exp-list` marked as obsolete;
           Use new `-pe` instead.
           ```
           DllExport -pe -help
           ```

* CHANGED: +Log option for IlMerge & ILRepack in the Wizard.

* CHANGED: Changed `-action Upgrade` logic same to `-action Configure`

* CHANGED: Make all paths relative as `$(DllExportDir)..\` in configured project files.

* CHANGED: Updated wrapper in offline version
           `offline.DllExport.1.8...zip` https://www.nuget.org/packages/DllExport/1.8

* CHANGED: Added netfx4sdk 1.2 helper to build using legacy tfm
           https://github.com/3F/netfx4sdk

* CHANGED: Updated
           * ILAsm 9.3.0
             https://github.com/3F/coreclr/releases/tag/9.3.0

           * ILMerge 3.0.41
             https://www.nuget.org/packages/ilmerge/3.0.41

           * Cecil 0.11.6
             https://github.com/jbevain/cecil/releases/tag/0.11.6

           * Conari 1.5.0
             https://github.com/3F/Conari/releases/tag/1.5

           * MvsSln 2.7 with enabled Huid implementation
             3F/MvsSln#51 (comment)

* NOTE: Tests for net9.0;net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;netstandard2.1;netstandard2.0;net472;...
        can be found in official repo https://github.com/3F/DllExport

        ~ https://github.com/3F/DllExport/tree/master/src/DllExport/assets
          https://github.com/3F/DllExport/tree/master/src/DllExport/UnitedTest

* NOTE: To upgrade to 1.8:
        DllExport -mgr-up -dxp-version 1.8
        or
        DllExport -action Upgrade -dxp-version 1.8

* NOTE: official manager can be found here:
        https://3F.github.io/DllExport/releases/latest/manager/
        or here:
        * https://github.com/3F/DllExport/releases/tag/1.8
        * https://www.nuget.org/packages/DllExport/1.8
3F added a commit that referenced this issue Feb 25, 2025
* NEW: Extends support for .NET 9, .NET 8, .NET 7,
       .NET 6, .NET 5, netcoreapp3.1, netstandard2.1, ...
       Issues: #219, #193, #132, #239

* NEW: Custom `.typref ...` & `.assembly extern ...` in the Wizard
       using modern 3F's IL Assembler 9.3+

* NEW: Support $-interpolation in modern .NET 9-6, Span, Memory, ...
       configure in the Wizard.

* NEW: New [Ref] packages control and related options.

* NEW: ImageBase + step control in multiple targeting.
       configure in the Wizard.

* NEW: New `DllExport -pe` keys:
          -list-addr, -list-ord, -list-all
          -magic, -num-functions, -base

* NEW: Official ILRepack support in Pre-processing; 2.0.39
       https://github.com/gluck/il-repack/releases/tag/2.0.39

* NEW: New PE Check option to control PE32/PE32+ arch.

* NEW: -action RecoverInit in addition to -action Recover;
       Recover to initial setup using predefined/exported data.

* NEW: Option to refresh intermediate module (obj) using modified. Issue #206.

* NEW: x86+x64 copy support for `Publish` targets. Related issue #224.
       `DllExportResolvePublish` property to control it.

* FIXED: Crashes or empty exports if code contains `.class extern forwarder` declarations.

* FIXED: error: syntax error at token '.' in .interfaceimpl type... Issue: #205.

* FIXED: Post-Proc: possible "The given key was not present in the dictionary."

* FIXED: Fixed Pre-Proc ILMerge for netcore.

* FIXED: Fix copying to own directory for "Provide x86+x64 assemblies"
         when no active dependencies.

* FIXED: Pre-Proc: fixed edit Exec raw command in the Wizard.

* FIXED: Fixed possible Incorrect RVA: 0 when PE Check is on.

* FIXED: Fixed -action Export: Parameter "unevaluatedValue" cannot be null.

* FIXED: Fixed Post-Proc DllExportDirX64 & DllExportDirX86 properties.

* FIXED: DllExportResolvePublish support for a single platform
         Related issue #235 or like.

* FIXED: Failed to write to log file ... because it is being used by another process. Issue #223.

* CHANGED: Execute `-action Restore` in case of loss of generated meta
         for the cases like ImplicitUsings=true etc.
         It will probably help with problems like #184.

* CHANGED: Improved support for nested projects using $(DllExportDir) etc.

* CHANGED: Improved managing `PlatformTarget` when applying the configuration.

* CHANGED: Improved TargetFrameworks multi-targeting support. ImageBase can be configured separately.

* CHANGED: Improved IsNetCoreBased logic for modern tfms.

* CHANGED: Improved cleaning logic at Pre-processing stage to delete correctly DllExport.Dll, Conari.dll
           and other assemblies from TargetDir when merging using [Ref] etc.

* CHANGED: `DllExport -action keys` are no longer case sensitive.

* CHANGED: Adds /PDB /OPTIMIZE and other types of PDB generation.
            Automatic option is relied on DebugType + Optimize + DebugSymbols properties:
            * Optimize: Optimize long instructions to short
            * PdbOptimize: +Create the PDB file without enabling debug info tracking
            * DebugOptimize: Enable JIT optimization, create PDB file, use implicit sequence points
            * Debug: Disable JIT optimization, create PDB file, use sequence points from PDB
            * DebugImpl: Disable JIT optimization, create PDB file, use implicit sequence points
            * Legacy True/False: Debug or Optimize

* CHANGED: Updated .PDB deletion logic according to ISymUnmanagedWriter problem.

* CHANGED: Use `wDxpMsgLevel` environment variable to control message level.

* CHANGED: Full integration with modern hMSBuild 2.4.1+
           https://github.com/3F/hMSBuild
           ```
           DllExport -hMSBuild -help
           ```

           GetNuTool now through hMSBuild engine:
           ```
           DllExport -hMSBuild -GetNuTool ...
           ```

* CHANGED: `DllExport -pe-exp-list` marked as obsolete;
           Use new `-pe` instead.
           ```
           DllExport -pe -help
           ```

* CHANGED: +Log option for IlMerge & ILRepack in the Wizard.

* CHANGED: Changed `-action Upgrade` logic same to `-action Configure`

* CHANGED: Make all paths relative as `$(DllExportDir)..\` in configured project files.

* CHANGED: Updated wrapper in offline version
           `offline.DllExport.1.8...zip` https://www.nuget.org/packages/DllExport/1.8

* CHANGED: Added netfx4sdk 1.2 helper to build using legacy tfm
           https://github.com/3F/netfx4sdk

* CHANGED: Updated
           * ILAsm 9.3.0
             https://github.com/3F/coreclr/releases/tag/9.3.0

           * ILMerge 3.0.41
             https://www.nuget.org/packages/ilmerge/3.0.41

           * Cecil 0.11.6
             https://github.com/jbevain/cecil/releases/tag/0.11.6

           * Conari 1.5.0
             https://github.com/3F/Conari/releases/tag/1.5

           * MvsSln 2.7 with enabled Huid implementation
             3F/MvsSln#51 (comment)

* NOTE: Tests for net9.0;net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;netstandard2.1;netstandard2.0;net472;...
        can be found in official repo https://github.com/3F/DllExport

        ~ https://github.com/3F/DllExport/tree/master/src/DllExport/assets
          https://github.com/3F/DllExport/tree/master/src/DllExport/UnitedTest

* NOTE: To upgrade to 1.8:
        DllExport -mgr-up -dxp-version 1.8
        or
        DllExport -action Upgrade -dxp-version 1.8

* NOTE: official manager can be found here:
        https://3F.github.io/DllExport/releases/latest/manager/
        or here:
        * https://github.com/3F/DllExport/releases/tag/1.8
        * https://www.nuget.org/packages/DllExport/1.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants