-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
LoadLibrary returns a 203 error code #240
Comments
Hello, Some Windows API functions like LoadLibrary/Ex, GetProcAddress can set the LastError > 0 when they succeed and some even vice versa. Moreover, the case for DllExport is too complicated in context of loading a regular native PE modules because DllExport's modified PE module will still contain imports record on mscoree for CLR init (stub _CorDllMain or _CorExeMain) and everything related in that chain. This, for example, can produce 126 (0x7E) and 127 (0x7F) even for valid and correct procs. That's why you need to check for a valid module/proc handle first, and only then GetLastError(). I checked your err_env.zip (thanks for the prepared example) but unfortunately 203 (0xCB) is not reproducible for me; <DllExportOurILAsm>true</DllExportOurILAsm>
<DllExportSysObjRebase>true</DllExportSysObjRebase> Regarding .NET 8 from your csproj: <TargetFramework>net8.0</TargetFramework> For DllExport 1.7.4 not all types are supported yet if used modern netcore-based target platforms. [DllExport]
public static int test_fn(int i) => i; your native c++ ...
((fn)GetProcAddress(lib, "test_fn"))(5);
// 5 Works well for me even for .NET 8 Let me know if there are still any problems with 203 (0xCB) |
Thanks for the swift answer, |
This is what I was talking about; The error code depends on the actual environment due to the chain I mentioned above. Do not use GetLastError() in order to understand the problem here. I need only information about handles, stack, crash, etc. when you actually call the export test_fn function.
both; your attached module looks correct What if netfx-based target platform? Try to step into test_fn when debugging at runtime from your c++ project (don't forget to enable Mixed debugger + disable 3F's IL Assembler because it doesn't produce the .line) Try with latest stable CI build and activate Refresh intermediate module to be sure: DllExport -mgr-up -pkg-link https://ci.appveyor.com/api/buildjobs/8aphdlsrgttj1pov/artifacts/bin/Release/DllExport.1.7.4.nupkg Or I reconfigured it for you: err_env_updated.zip (Unpack - Open err_env.sln in VS IDE - Run F5 - Step Into F11) |
Thanks a lot, your provided example seems to work. as for the error, sorry I didn't understood your question properly first time, anyway here is the exception, that I am getting:
As for the library and function pointer, they store addresses, that seems to be valid, both have the following text in the debugger: |
Good!
Is this an exception was for your initial .NET 8 (coreclr) ? or for .NET Framework 8.1 ? Can you check the same err_env_updated.zip but for .NET 8 ? |
Thanks for the provided sources one more time, this example seems to work. However, it works not totally as expected. |
This is actually expected behavior when using my 3F's assembler: #23 (comment) Also note: 1.7.4 does not fully* support modern .NET 8 (*err_env_updated_net80.zip works correctly as you can see). It is planned to resolve in 1.8
Looks like a debugger issue because it is also reproduced for netfx with original assembler when debugger type is Native only; While the Mixed type fixes the case. I can try to review the problem after 1.8 if it really bothers you; please create a new issue. Regarding GetLastError(), everything that I said above. Thanks for the details you provided! |
@3F Hi again, can you please tell me what changes have you made to the projects, so it works as expected? |
@sat0sh1c Which one? You can use any diff tool on .csproj from err_env_updated.zip & err_env_updated_net80.zip + "Refresh intermediate module (obj) using modified" planned for 1.8; available in latest CI build using command:
And "Use 3F's IL Assembler" + "Rebase" for err_env_updated_net80.zip + updated debug options including .vcxproj |
Steps to reproduce:
Load the project inside the zip attached to this post and try to run it. The build works just fine, but in unmanaged environment there is an error, when I am trying to load the library via
LoadLibrary
DllExport -version 1.7.4
:Information from
Data
tab or log data:log.txt
Demo Project files / Samples / etc.:
err_env.zip
The text was updated successfully, but these errors were encountered: