I'm calling a C++ DLL from C# via P/Invoke using DllImport. The DLL is produced by a third party and is x86 only (so our C# code is built as x86 as well).
If I call a certain function on the DLL from a console application, I always get one result which is correct. The function takes a file path and extracts some information from the file.
The signature of the function is:
private static extern int Function(
string str1,
int bool1,
ref uint outUint1,
ref uint outUint2,
ref uint outUint3,
ref double outDouble1,
ref double outDouble2,
StringBuilder outStr1);
And the unexpected result is in one of the ref uint
parameters.
If I create a unit test and call the exact same code (with all parameters and such hardcoded), I get an entirely different result, which is incorrect. The incorrect result is always the same. I've tried both MSTest and NUnit tests using various different runners with the same result.
Cases producing correct results:
- Console app
- Winforms app
- Console app running the code but launched from a Unit Test (NUnit)
Cases producing incorrect results:
- Test run from Resharper Test Runner (NUnit)
- Test run from Visual Studio Test Runner (MSTest)
- Test run from NUnit GUI Test Runner
- Test run from NUnit Console Test Runner
My test environment is Windows 8 and the C# is built for x86 targeting .NET framework 4.
Do any of you have any ideas about what's causing this issue or what I can do to debug it further?
I will definitely be attempting to contact the third party that created the DLL, but having a good idea about exactly what's causing this issue would substantially increase the chance of it getting resolved.