Closed joeloff closed 8 months ago
Thanks for your report. When I try with 0.3.49-beta, to generate only WinVerifyTrust
and use this code:
using static Windows.Win32.PInvoke;
unsafe
{
WinVerifyTrust(default, default, default);
}
I get an AV, which as you say is expected given the null pointers. I don't get an EntryPointNotFoundException
.
When I compare your non-CsWin32 simple repro to what CsWin32 minimally generates, it looks equivalent.
So then I took your full repro and it succeeded too. But it's only lucky, because you have at least one bug, in that your only pin Path.GetFullPath(path)
long enough to set a pointer, but that pointer can become invalid as soon as you exit the fixed
block, which is before the native code uses the pointer.
Oh man, that never registered with me, I'll fix that up right away.
The bug persists though in my original project.
I created a 3rd project, which only had the minimal API and calling it with default parameters work just fine, no entry point issue. I'm sure this is going to be something silly - this has to be corrupted memory or something getting overwritten. I'll keep the issue open for now and update with anything I discover.
Closing this. In my haste, I decided to name my console app wintrust, so it created a wintrust.dll which is not the same as wintrust.dll in system32, which explains why my random consoleapp123 works just fine.
Actual behavior
Created a .NET 7.0 console application that calls into
WinVerifyTrust
. I run into the following exceptionSystem.EntryPointNotFoundException: Unable to find an entry point named 'WinVerifyTrust' in DLL 'WINTRUST.dll'
I created a second console application without CsWin32 with the following:
This obviously still fails because of the null pointers, but the external method is successfully resolved. I also ran
dumpbin /exports wintrust.dll
just to make sure.The only thing I can think of is that perhaps I messed up the data structures and somehow overwrite the function pointer returned when the library is loaded.
Expected behavior
Expected the API call to succeed.
Repro steps
NativeMethods.txt
content:NativeMethods.json
content (if present):Any of your own code that should be shared?
Context
0.3.46-beta
net7.0
LangVersion
(if explicitly set by project): [e.g.9
]