Here a little test code illustrating the problem:
Compiling configurations:
Common Language Runtime Support: /clr
C++ Language
Error message:
Error 4 error C2065: ‘DataContractSerializer’ : undeclared identifier C:…\SerializationTest.cpp 21 1 SerializationTest
The code:
// SerializationTest.cpp : main project file.
#include "stdafx.h"
using namespace System::Collections::Generic;
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Runtime::Serialization;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
Dictionary<System::String^, System::Double>^ teste = gcnew Dictionary<System::String^, System::Double>();
teste->Add("Teste1",2);
teste->Add("Teste2",4);
DataContractSerializer^ serializer = gcnew DataContractSerializer(teste->GetType());
StringWriter^ writer = gcnew StringWriter();
XmlTextWriter^ stm = gcnew XmlTextWriter(writer);
serializer->WriteObject(stm, teste);
Console::WriteLine(writer->ToString());
return 0;
}
It sounds simply like you’re missing a reference to System.Runtime.Serialization.dll (which is required in addition to the
usingdirective):