Thread local storage with __declspec(thread) fails in C++/CLI
- by EFrank
I'm working on a project where we mix .NET code and native C++ code via a C++/CLI layer. In this solution I want to use Thread Local Storage via the __declspec(thread) declaration:
__declspec(thread) int lastId = 0;
However, at the first access of the variable, I get a NullReferenceException.
To be more precise, the declaration is done within a ref class (a .NET class implemented in C++/CLI).
I have already read something about __declspec(thread) does not work with delay loaded DLLs.
Am I using delay loaded DLLs automatically if I use .NET?