By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

System.AccessViolationException: Attempted to read or write protected memory

P: 2
Hi friends,

I am facing one serious problem in my application.
I am trying to open dicom image file (.dcm) has size around 400 MB.
But I am getting and unhandy exceptions,

Some time,

{System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at ?readMedia@BASE_SESSION_CLASS@@$$FQAEPAVFILE_DATAS ET_CLASS@@V?$basic_string@DU?$char_traits@D@std@@V ?$allocator@D@2@@std@@W4MEDIA_FILE_CONTENT_TYPE_EN UM@@000_N2@Z(BASE_SESSION_CLASS* , basic_string<char\,std::char_traits<char>\,std::al locator<char> >* , Int32 , basic_string<char\,std::char_traits<char>\,std::al locator<char> >* , basic_string<char\,std::char_traits<char>\,std::al locator<char> >* , basic_string<char\,std::char_traits<char>\,std::al locator<char> >* , Boolean , Boolean )
at Wrappers.MBaseSession.ReadMedia(String pFileName)
at Dvtk.Sessions.Session.ReadFile(String mediaFileName)
at DvtkHighLevelInterface.Dicom.Files.DicomFile.Read( String fullFileName, ScriptSession dvtkScriptSession)
at DvtkHighLevelInterface.Dicom.Files.DicomFile.Read( String fullFileName, String[] definitionFilesFullName)
at _3disytems.DicomAnonymiserLibrary.DicomImageProces sor.ModifyDicomFile(String filePath) in E:\Projects\Working\Dicom Project\DicomEditorLibrary\DicomImageProcessor.cs: line 63}


and Some times

{System.Runtime.InteropServices.SEHException: External component has thrown an exception.
at ?readMedia@BASE_SESSION_CLASS@@$$FQAEPAVFILE_DATAS ET_CLASS@@V?$basic_string@DU?$char_traits@D@std@@V ?$allocator@D@2@@std@@W4MEDIA_FILE_CONTENT_TYPE_EN UM@@000_N2@Z(BASE_SESSION_CLASS* , basic_string<char\,std::char_traits<char>\,std::al locator<char> >* , Int32 , basic_string<char\,std::char_traits<char>\,std::al locator<char> >* , basic_string<char\,std::char_traits<char>\,std::al locator<char> >* , basic_string<char\,std::char_traits<char>\,std::al locator<char> >* , Boolean , Boolean )
at Wrappers.MBaseSession.ReadMedia(String pFileName)
at Dvtk.Sessions.Session.ReadFile(String mediaFileName)
at DvtkHighLevelInterface.Dicom.Files.DicomFile.Read( String fullFileName, ScriptSession dvtkScriptSession)
at DvtkHighLevelInterface.Dicom.Files.DicomFile.Read( String fullFileName, String[] definitionFilesFullName)
at _3disytems.DicomAnonymiserLibrary.DicomImageProces sor.ModifyDicomFile(String filePath) in E:\Projects\Working\Dicom Project\DicomEditorLibrary\DicomImageProcessor.cs: line 63}


These exception not getting for every files, only for large files when I am trying to read them.

I am using DVTK Library for Dicom images provided by DVTK. It's open source
http://www.dvtk.org

Following code ex I am using..

Expand|Select|Wrap|Line Numbers
  1. public static void ModifyDicomFile(string filePath)
  2.         {
  3.             DicomFile theDicomFile;
  4.             try
  5.             {
  6.                 theDicomFile = new DicomFile();
  7.                 theDicomFile.Read(filePath);
  8.  
  9.                 if (attrInfo.PatientName == null || attrInfo.PatientName == "" || attrInfo.PatientID == null || attrInfo.PatientID == "" || attrInfo.PatientDOB == null || attrInfo.PatientDOB == "")
  10.                     Logger.Log(dirSettings.LogDirectory, "some information of Patient is missing in App.config");
  11.  
  12.                 theDicomFile.DataSet.Set("0x00100010", VR.PN, attrInfo.PatientName);
  13.                 theDicomFile.DataSet.Set("0x00100020", VR.LO, attrInfo.PatientID);
  14.                 theDicomFile.DataSet.Set("0x00100030", VR.DA, attrInfo.PatientDOB);
  15.  
  16.                 string relPath;
  17.  
  18.                 if (!filePath.Contains(".dcm"))
  19.                 {
  20.                     relPath = dirSettings.TargetDirectory + filePath.Substring(dirSettings.SourceDirectory.Length) + ".dcm";
  21.                 }
  22.                 else
  23.                 {
  24.                     relPath = dirSettings.TargetDirectory + filePath.Substring(dirSettings.SourceDirectory.Length);
  25.                 }
  26.  
  27.                 theDicomFile.Write(relPath);
  28.  
  29.                 // File.Delete(filePath);
  30.             }
  31.             catch (Exception e)
  32.             {
  33.                 Logger.Log(dirSettings.LogDirectory, "Error: Dicom File Modification : " + e.Message);
  34.             }
  35.         }  

I am want to tell you that this is working for small files(2-5mb) but it giving problem me when I am trying to read 400MB files

Please solve this problem.
This is .Dot net only

Thanks,
Manesh
Jan 15 '10 #1
Share this Question
Share on Google+
3 Replies


tlhintoq
Expert 2.5K+
P: 3,525
How much free memory does your PC have?
Maybe you are just running out of RAM.
Jan 15 '10 #2

P: 2
Hi,

I have 2 GB of RAM, 4-8 GB Virtual Memory set. And when I run the application lot of memory unused.

but still it is not working.
Jan 15 '10 #3

alexis4
100+
P: 113
Access violation exceptions come from bad interop calls or unmanaged code. Do you have any dll function calls? Do you use unsafe code? Are low level API calls involved with your project?
Or you can simply run out of memory as tlhintoq said.. Or a part of your memory could be ruined.
This thing is tricky, so give us a little more clues. Above how much mb does this happen? It happens always on the same files or sometimes you open it and sometimes not? Are you using an unhandled exception event to catch it and it is by-passed?
Jan 15 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.