Attempted to read or write protected memory.This is often an indication that other memory is corrupt

Posted by Chinna373 under C# on 5/21/2012 | Points: 10 | Views : 1710 | Status : [Member] | Replies : 0
I am getting the the exception "Attempted to read or write protected memory.This is often an indication that other memory is corrupt" because of below code. Could you please help in the below code?

private void Configure()
{
try
{
string filePath = string.Empty;
FileStream fsRead;
BinaryReader binRead;
int rtnVal = 0;

filePath = GetBaseDirectory(@"\") + "Sample.BIN";
if (File.Exists(filePath) == false) return;

fsRead = new FileStream(@filePath, FileMode.Open);
binRead = new BinaryReader(fsRead);
if (binRead != null && binRead.BaseStream.Length > 0)
{
int MsI = -1;
binRead.BaseStream.Seek(0, SeekOrigin.Begin);
CRsiFkeyData pFkeyData = new CRsiFkeyData();
byte[] byteArray = binRead.ReadBytes(Convert.ToInt32(binRead.BaseStream.Length.ToString()));

while (++MsI < binRead.BaseStream.Length)
{

unsafe
{
pFkeyData.data[MsI] = byteArray[MsI];
}
}

rtnVal = objRsiHandReader.CmdPutFkeyData(pFkeyData);
binRead.Close();
}
fsRead.Close();
}
catch (Exception Ex)
{
Global.MakeEntry(Ex.Message + " Configure");
}
}




Responses

(No response found.)

Login to post response