I got this strange issue when stepping into code when debugging a 32-bit mixed mode assembly. The stripped down version of the code looks like this:
public ref class FooClass {
public:
FooClass();
};
FooClass::FooClass(){
// Note: doesn't matter what code is in here, as long as it is native
char test[10];
memset((void*)test, 0, sizeof(test));
}
This class is then instantiated in another class:
FooClass^ BarClass::Test() {
FooClass^ addr = gcnew FooClass();
return addr;
}
..which again is instantiated in a C# console app:
class Program
{
static void Main(string[] args)
{
BarClass bar = new BarClass();
FooClass foo = bar.Test();
}
}
When stepping through the code, and into the FooClass constructor, I get an exception
(note: removed argument info for the sake of less mess):
ntdll.dll!_NtTraceEvent@16() Unknown
ntdll.dll!EtwpEventWriteFull() Unknown
ntdll.dll!_EtwEventWrite@20() Unknown
clrjit.dll!Compiler::lvaInitTypeRef() Line 253 C++
clrjit.dll!Compiler::compCompileHelper(...) Line 3489 C++
clrjit.dll!Compiler::compCompile(...) Line 3092 C++
clrjit.dll!jitNativeCode(...) Line 4063 C++
clrjit.dll!CILJit::compileMethod(...) Line 180 C++
[Managed to Native Transition]
> FooBar.dll!FooBar::BarClass::Test() Line 16 C++
ConsoleApp.exe!ConsoleApp.Program.Main(string[] args) Line 15 C#
However, if I just add breakpoints in the constructors and just run to next breakpoint, the code runs fine.
Also, when removing native code, it runs fine.
This issue does not occur in 64-bit mode. I crosschecked for settings, but can't really see anything special.
There are no 3rd party dll's, all the native code is compiled into the assembly.
This is not my first C++/CLI project, but first time I do it in VS2015.
From the comments in my original question, the following was suggested:
This fixed the issue.