This is a little bit of a weird one, and my first foray into the world of .net so I'm hoping that I'm missing something fundamental :) Background:
I have a native/Qt c++ DLL that I am wrapping for use in .NET, C# in this case. I have a Qt app that uses this DLL successfully, without memory leaks, etc. I have created a c++/CLI wrapper for this library and I can call into the native code through it successfully. However, I've noticed that depending on how I first interact with the managed DLL (and hence the native DLL), I see AccessViolation exceptions.
If I allocate an object out of the native DLL on the process (not .net) heap first, everything works as expected. But if I interact with an object from the native DLL by creating it on the stack, then subsequently allocate a native object on the heap, I later get AccessViolation exceptions in unrelated native DLL code. In fact, I only have to allocate the native object (and never reference it again) to see these errors.
The stack vs. heap issue may be a red herring of course, but it's 100% reproducible so seems like at least a good lead to hunt down. Any tips? Thanks!