System.AccessViolationException: Attempted to read or write protected memory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maneshborase
    New Member
    • Jan 2010
    • 2

    System.AccessViolationException: Attempted to read or write protected memory

    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.AccessV iolationExcepti on: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    at ?readMedia@BASE _SESSION_CLASS@ @$$FQAEPAVFILE_ DATASET_CLASS@@ V?$basic_string @DU?$char_trait s@D@std@@V?$all ocator@D@2@@std @@W4MEDIA_FILE_ CONTENT_TYPE_EN UM@@000_N2@Z(BA SE_SESSION_CLAS S* , basic_string<ch ar\,std::char_t raits<char>\,st d::allocator<ch ar> >* , Int32 , basic_string<ch ar\,std::char_t raits<char>\,st d::allocator<ch ar> >* , basic_string<ch ar\,std::char_t raits<char>\,st d::allocator<ch ar> >* , basic_string<ch ar\,std::char_t raits<char>\,st d::allocator<ch ar> >* , Boolean , Boolean )
    at Wrappers.MBaseS ession.ReadMedi a(String pFileName)
    at Dvtk.Sessions.S ession.ReadFile (String mediaFileName)
    at DvtkHighLevelIn terface.Dicom.F iles.DicomFile. Read(String fullFileName, ScriptSession dvtkScriptSessi on)
    at DvtkHighLevelIn terface.Dicom.F iles.DicomFile. Read(String fullFileName, String[] definitionFiles FullName)
    at _3disytems.Dico mAnonymiserLibr ary.DicomImageP rocessor.Modify DicomFile(Strin g filePath) in E:\Projects\Wor king\Dicom Project\DicomEd itorLibrary\Dic omImageProcesso r.cs:line 63}


    and Some times

    {System.Runtime .InteropService s.SEHException: External component has thrown an exception.
    at ?readMedia@BASE _SESSION_CLASS@ @$$FQAEPAVFILE_ DATASET_CLASS@@ V?$basic_string @DU?$char_trait s@D@std@@V?$all ocator@D@2@@std @@W4MEDIA_FILE_ CONTENT_TYPE_EN UM@@000_N2@Z(BA SE_SESSION_CLAS S* , basic_string<ch ar\,std::char_t raits<char>\,st d::allocator<ch ar> >* , Int32 , basic_string<ch ar\,std::char_t raits<char>\,st d::allocator<ch ar> >* , basic_string<ch ar\,std::char_t raits<char>\,st d::allocator<ch ar> >* , basic_string<ch ar\,std::char_t raits<char>\,st d::allocator<ch ar> >* , Boolean , Boolean )
    at Wrappers.MBaseS ession.ReadMedi a(String pFileName)
    at Dvtk.Sessions.S ession.ReadFile (String mediaFileName)
    at DvtkHighLevelIn terface.Dicom.F iles.DicomFile. Read(String fullFileName, ScriptSession dvtkScriptSessi on)
    at DvtkHighLevelIn terface.Dicom.F iles.DicomFile. Read(String fullFileName, String[] definitionFiles FullName)
    at _3disytems.Dico mAnonymiserLibr ary.DicomImageP rocessor.Modify DicomFile(Strin g filePath) in E:\Projects\Wor king\Dicom Project\DicomEd itorLibrary\Dic omImageProcesso r.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..

    Code:
    public static void ModifyDicomFile(string filePath)
            {
                DicomFile theDicomFile;
                try
                {
                    theDicomFile = new DicomFile();
                    theDicomFile.Read(filePath);
    
                    if (attrInfo.PatientName == null || attrInfo.PatientName == "" || attrInfo.PatientID == null || attrInfo.PatientID == "" || attrInfo.PatientDOB == null || attrInfo.PatientDOB == "")
                        Logger.Log(dirSettings.LogDirectory, "some information of Patient is missing in App.config");
    
                    theDicomFile.DataSet.Set("0x00100010", VR.PN, attrInfo.PatientName);
                    theDicomFile.DataSet.Set("0x00100020", VR.LO, attrInfo.PatientID);
                    theDicomFile.DataSet.Set("0x00100030", VR.DA, attrInfo.PatientDOB);
    
                    string relPath;
    
                    if (!filePath.Contains(".dcm"))
                    {
                        relPath = dirSettings.TargetDirectory + filePath.Substring(dirSettings.SourceDirectory.Length) + ".dcm";
                    }
                    else
                    {
                        relPath = dirSettings.TargetDirectory + filePath.Substring(dirSettings.SourceDirectory.Length);
                    }
    
                    theDicomFile.Write(relPath);
    
                    // File.Delete(filePath);
                }
                catch (Exception e)
                {
                    Logger.Log(dirSettings.LogDirectory, "Error: Dicom File Modification : " + e.Message);
                }
            }

    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
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    How much free memory does your PC have?
    Maybe you are just running out of RAM.

    Comment

    • maneshborase
      New Member
      • Jan 2010
      • 2

      #3
      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.

      Comment

      • alexis4
        New Member
        • Dec 2009
        • 113

        #4
        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?

        Comment

        Working...