Unable to update header tags and save dicom file

Hi,
I am trying to create an image ,update some tags and save image as dicom file. If i set Meta Data Dictionary to image , writer is throwing an exception. Below is the code

typedef itk::Image<signed short , 2 >   ImageType;
	typedef itk::GDCMImageIO       ImageIOType;
	ImageIOType::Pointer dicomIO = ImageIOType::New();
	dicomIO->LoadPrivateTagsOn();
int recordLength = 17400;
	int numberOfAscans =10;
	
	ImageType::RegionType region;
	ImageType::SizeType size;
	size[0] = recordLength;
	size[1] = numberOfAscans;
	region.SetSize(size);
	
	signed short tempValue = 0;

	ImageType::Pointer bscanData = ImageType::New();
	bscanData->SetRegions(region);
	bscanData->Allocate();
	bscanData->FillBuffer(tempValue);
	
	for (int ascanIndex = 0; ascanIndex < numberOfAscans; ascanIndex++)
	{
		
		System::IO::StreamReader^ reader = gcnew System::IO::StreamReader(filesInDirectory[ascanIndex]);
		int ascanPointIndex = 0;
		while (!reader->EndOfStream)
		{
			cli::array<String^>^ pointValue = reader->ReadLine()->Split('\t');
		
			double currentVal = Convert::ToDouble(pointValue[1]);
			signed short valueToFit = currentVal * -1000;
			ImageType::IndexType currentIndex;
			currentIndex[0] = ascanPointIndex; currentIndex[1] = ascanIndex;
			bscanData->SetPixel(currentIndex, valueToFit);
			ascanPointIndex++;
		}
	}
	bscanData->Update();

	using DictionaryType = itk::MetaDataDictionary;
	DictionaryType dictionary;
	
	std::string sopId("0008|0016");
	std::string sopIdValue("1.2.840.10008.5.1.4.1.1.6.1");
	itk::EncapsulateMetaData<std::string>(dictionary, sopId, sopIdValue);
	

		std::string prf("0018|6032");
		std::string prfValue("100");
		itk::EncapsulateMetaData<std::string>(dictionary, prf, prfValue);
		


		std::string rescaleIntercept("0028|1052");
		std::string rescaleInterceptValue("0");
		itk::EncapsulateMetaData<std::string>(dictionary, rescaleIntercept, rescaleInterceptValue);
		


		std::string rescaleSlope("0028|1053");
		std::string rescaleSlopeValue("-1000");
		itk::EncapsulateMetaData<std::string>(dictionary, rescaleSlope, rescaleSlopeValue);

	dicomIO->SetMetaDataDictionary(dictionary);
	bscanData->SetMetaDataDictionary(dictionary);
typedef itk::ImageFileWriter< ImageType > WriterType;
	WriterType::Pointer writer = WriterType::New();
	writer->SetFileName("D:\\TempBscanDiconde.dcm");
	writer->SetImageIO(dicomIO);
	writer->SetInput(bscanData);
	writer->SetMetaDataDictionary(dictionary);
	try
	{
		writer->Update();
	}
	catch (itk::ExceptionObject& error)
	{
		std::cerr << "Error: " << error << std::endl;
	}