1

I recently installed Visual Studio 2012 and tried recompiling an existing project which is a mixed mode C++ application with a little C++/cli used to access a .net assembly required by the app.

Part of the C++/CLI implementation uses a ReaderWriterLockSlim class to protect access to a dictionary from multiple threads.

This all compiles and works fine with VS2010. After upgrading to VS0212 and .Net 4.5 however, the project now fails to compile since it cannot find the ReaderWriterLockSlim in the System::Threading namespace.

I'm fairly sure the installation is fine since I can create a new C# project and use ReaderWriterLockSlim without any problems.

A new C++ project shown below also fails. I cant find any reference to this class being deliberately removed for C++/CLI users either on here or google. Has anyone else had a similiar experience.

#include "stdafx.h"
using namespace System::Threading;

int _tmain(int argc, _TCHAR* argv[])
{
    ReaderWriterLockSlim^ rwlock = gcnew ReaderWriterLockSlim();

    return 0;
}
  • You said that you get this error on a C++ project that you converted to C++/CLI. What happens if you create a C++/CLI project from scratch? – David Yaw Feb 07 '13 at 13:17

1 Answers1

4

Be sure to pay attention to the MSDN Library article for the class when you have a problem like this. Right at the top of the article it shows you which reference assembly is required to use the class:

Assembly: System.Core (in System.Core.dll)

Which is not included by default in the C++/CLI project template. Fix that with Project + Properties, Common Properties, Framework and References. Review the "References" list. Click the Add New Reference button and tick System.Core from the Assemblies + Framework list.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thank you, that fixed the problem. Never thought to check that since ReaderWriterLock was available but ReaderWriterLockSlim wasn't. It turns out ReaderWriterLock is in mscorelib.dll. – user1200305 Feb 07 '13 at 15:15
  • Thanks! The latest docs show it in the System.Threading.dll assembly, which as far as I can tell does not actually exist, at least in .NET 4.6. – Cameron Nov 10 '20 at 19:54
  • Pay attention to Version (upper left combo). Pick the right one to get [this](https://learn.microsoft.com/en-us/dotnet/api/system.threading.readerwriterlockslim?redirectedfrom=MSDN&view=netframework-4.6). – Hans Passant Nov 10 '20 at 20:32