question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

External Exception E0434352 using netcore

See original GitHub issue

Hello,

I’m currently struggling with the implementation of an exported .NET Core function in my Delphi application. Just before I submitted this issue I also tried to implement the same dll with the same function in C++. Both implementations threw the same error 0xE0434352. When I inspect the dll using a dependency inspector, the right dependencies are set and the function is correctly exported.

  • v1.7beta3:
  • Manager: Tried both x86, x64 and Direct-Mod/Cecil in all possible variants.
  • Project type: .NET Core 3.1.100 Class Library
  • Environment: Visual Studio 2019 v16.4.1, Windows SDK 10.0.17763.0

Used configuration:

  • 64 bit (bot Delphi and .NET Core)

Source

ExportsDemo.dll -> Exports.cs:

using System.Windows.Forms;

namespace ExportsDemo
{
    public static class Exports
    {
        [DllExport]
        public static void DemoProc()
        {
            MessageBox.Show("Hello world!");
        }
    }
}

ExportsDemo -> ExportsDemo.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <PropertyGroup>
    <DllExportIdent>19A9E616-EECD-4703-897E-4BD8A257C0F0</DllExportIdent>
    <DllExportMetaLibName>DllExport.dll</DllExportMetaLibName>
    <DllExportNamespace>ExportsDemo</DllExportNamespace>
    <DllExportDDNSCecil>true</DllExportDDNSCecil>
    <PlatformTarget>x64</PlatformTarget>
    <DllExportOrdinalsBase>1</DllExportOrdinalsBase>
    <DllExportGenExpLib>false</DllExportGenExpLib>
    <DllExportOurILAsm>false</DllExportOurILAsm>
    <DllExportSysObjRebase>false</DllExportSysObjRebase>
    <DllExportLeaveIntermediateFiles>false</DllExportLeaveIntermediateFiles>
    <DllExportTimeout>30000</DllExportTimeout>
    <DllExportPeCheck>2</DllExportPeCheck>
    <DllExportPatches>0</DllExportPatches>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="DllExport, PublicKeyToken=8337224c9ad9e356">
      <HintPath>$(SolutionDir)packages\DllExport.1.7.0-beta3\gcache\$(DllExportMetaXBase)\$(DllExportNamespace)\$(DllExportMetaLibName)</HintPath>
      <Private>False</Private>
      <SpecificVersion>False</SpecificVersion>
    </Reference>
    <Reference Include="System.Windows.Forms">
      <HintPath>..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Windows.Forms.dll</HintPath>
    </Reference>
  </ItemGroup>
  <ImportGroup Label=".NET DllExport">
    <Import Project="$(SolutionDir)packages\DllExport.1.7.0-beta3\tools\net.r_eg.DllExport.targets" Condition="Exists($([MSBuild]::Escape('$(SolutionDir)packages\DllExport.1.7.0-beta3\tools\net.r_eg.DllExport.targets')))" Label="8337224c9ad9e356" />
  </ImportGroup>
  <Target Name="DllExportRestorePkg" BeforeTargets="PrepareForBuild">
    <Error Condition="!Exists('$(SolutionDir)DllExport.bat')" Text="DllExport.bat is not found. Path: '$(SolutionDir)' - https://github.com/3F/DllExport" />
    <Exec Condition="('$(DllExportModImported)' != 'true' Or !Exists('$(SolutionDir)packages\DllExport.1.7.0-beta3\tools\net.r_eg.DllExport.targets')) And Exists('$(SolutionDir)DllExport.bat')" Command="DllExport.bat  -action Restore" WorkingDirectory="$(SolutionDir)" />
  </Target>
  <Target Name="DllExportRPkgDynamicImport" BeforeTargets="PostBuildEvent" DependsOnTargets="GetFrameworkPaths" Condition="'$(DllExportModImported)' != 'true' And '$(DllExportRPkgDyn)' != 'false'">
    <MSBuild BuildInParallel="true" UseResultsCache="true" Projects="$(MSBuildProjectFullPath)" Properties="DllExportRPkgDyn=true" Targets="Build" />
  </Target>
</Project>

C++ Project (PlusPlusDemo):

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

typedef int(__stdcall *f_funci)();

int main()
{
	HINSTANCE hGetProcIDDLL = LoadLibraryA("C:\\Users\\psn\\Desktop\\ExportsDemo.dll");

	if (!hGetProcIDDLL) {
		std::cout << "could not load the dynamic library" << std::endl;
		return EXIT_FAILURE;
	}

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

	funci();
	return EXIT_SUCCESS;
}

(I don’t really know the syntax of C++, just wanted to make sure the exception doesn’t belong to Delphi.)


Logs

C++ Exception: Unhandled exception at 0x00007FFB9336A839 (KernelBase.dll) in PlusPlusDemo.exe: 0xE0434352 (parameters: 0xFFFFFFFF80070002, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFB85F00000).

C++ CallStack:

KernelBase.dll!00007ffb9336a839()
clr.dll!00007ffb85f1a3f1()
clr.dll!00007ffb860ee7d9()
clr.dll!00007ffb86338585()
mscoreei.dll!00007ffb869fb26a()
mscoreei.dll!00007ffb86a099c2()
mscoreei.dll!00007ffb869e644e()
PlusPlusDemo.exe!main() Line 27
PlusPlusDemo.exe!invoke_main() Line 79
PlusPlusDemo.exe!__scrt_common_main_seh() Line 288
PlusPlusDemo.exe!__scrt_common_main() Line 331
PlusPlusDemo.exe!mainCRTStartup() Line 17
kernel32.dll!00007ffb940c7bd4()
ntdll.dll!00007ffb9562ced1()

Output of Delphi using the Visual Studio Debugger: VS2019_Delphi.log

Thank you in advance for the time and effort you put in this project.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
3Fcommented, Dec 16, 2019

Thank you in advance for the time and effort you put in this project.

Yes, recent 2 years have been very difficult for me 😦 And it was very difficult to combine all that with opensource activities. Really hard for my time and generally for me personally.

But I really like that all this are still helpful, and I still can continue develop something like this. Who follows me also knows that I had plan (and still have, see related #90) for native implementation. But today we’re still using this through ilasm and through my custom assembler features for .NET Core support, as you can see. Well, time will tell. I’m still alive and this is good point to continue develop something in OSS and at all 😃

I want to thanks again to all who supported me! Thank you, guys!

This project personally aggregated a bit of sum (especially when comparing with stars on github with my other projects). For all this years it was just about $80 for DllExport 😃 Soon I will try count this in details and personally donate to Robert and Cecil project something from that amount.

1reaction
phillsonntagcommented, Dec 18, 2019

Finally! It works, thank you very much for your help. The rebase did it. I missed something, but it finally works now. THANKS! 😄

EDIT: I also tried to define the stdcall before, but it didn’t work either, so I tried everything I could find 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve Error external exception E0434352 on ...
1. Obviously, your C# DLL causes an exception and Delphi can't handle such an exception. Ensure that your DLL can't raise an exception....
Read more >
ABL GUI client crashes with Windows error E0434352
The Windows error E0434352 means there is a problem with the .NET installation. Resolution. Attempt the following steps: 1) Reboot ...
Read more >
Why do I keep getting exception code e0434352?
Exception code e0434352 is the exception code used internally by the CLR to represent most exceptions(*). Regardless of if you throw a System....
Read more >
How to resolve Error external exception E0434352 on calling ...
This post Using a C# DLL in Delphi only uses the first function parameter help me to correct my code. New C# code...
Read more >
How to solve unknown software exception 0xe0434352
1. Press Windows Key+R and type “appwiz.cpl“. 2. Then, click on “OK“. ... This will open “Program and Features“. 3. Look for the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found