0

I want to store an image data in an array byte into a dictionary.

int img_sz = img0->width * img0->height * img0->nChannels;

array <Byte>^ hh = gcnew array<Byte> (img_sz);

Marshal::Copy( (IntPtr)img->imageData, hh, 0, img_sz );

Dictionary<String^,array< Byte >^>^ myResult = gcnew Dictionary<String^,array< Byte >^>(); 

myResult->Add("OVERVIEW",hh);

Once it reaches the line myResult->Add("OVERVIEW",hh);

I am getting an :An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

1 Answer 1

0

Check for duplicate keys. Dictionary::Add can't be used to replace existing data.

You can see the error explained in the documentation right here. It specifically says

ArgumentException               An element with the same key already exists in the Dictionary.

1
  • If you want to replace, myResult["OVERVIEW"] = hh; is the way to go.
    – David Yaw
    Jul 10, 2012 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.