I have C++ CLR project with both managed and unmanaged code. In this project I loop through list of cryptoproviders and search for suitable.
So I use functions <br /> CryptEnumProvidersA <br /> CryptAcquireContextA
I have C# project which uses C++ project. When I call the method to loop through list of cryptoproviders twice, my application crashes. And it crashes on CryptAcquireContextA. And only on "Aloaha Cryptographic Provider".
When i use debug mode, it also crashes. But when i use debug mode, set breakpoint and pass through code with F10, it works fine.
When i carry out C++ code to separate project, it works fine in all cases.
So, I have two questions here:<br /> 1) How such a crash possible? And why it happens?<br /> 2) How can I call CryptAcquireContextA to handle such a crash?<br />
My considerations.<br /> 1) Some troubles with memory. I was searching for memory leaks, but I didn't find any.<br /> 2) I tried to use try-catch, but with no result, CryptAcquireContextA crashes anyway. I would like to use function like "CryptIsValidProvider" or "CryptPingProvider", but I didn't find it.Answer1:
If it works when single-stepping, it's probably a race condition (you're paused in the debugger long enough for some other process or driver to make progress).
Does it matter how much code you single-step through? Does putting a
Sleep instead of a breakpoint right before the
CryptAcquireContextA call also work?