Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why?

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why?

Scheduled Pinned Locked Moved C#
csharpvisual-studiodebuggingperformancehelp
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    turbosupramk3
    wrote on last edited by
    #1

    I'm getting this error message on my laptop (win7 64bit/visual studio 2012 express), but not my desktop (win7 64bit/visual studio 2012 pro), code is unchanged. This is happening when my code runs through

    Quote:

    var versionPtr = GetPropellerVersion();

    Which is a dll import call via the code below, so it has something to do with the unmanaged code, but I'm a bit confused as to why? I believe the dll is 32 bit, so I've set the project to force x86, but I'm unsure as to what else could cause this? The project is set to 'copy always' the dll as well. I've also tried it in debug and release mode, same conflicting results. Does anyone have any ideas? Thanks for reading.

    Quote:

    [DllImport("Propellent.dll", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr GetPropellerVersion();

    Quote:

    Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at program.GetPropellerVersion() at program.btnDetectPort_Click(Object sender, EventArgs e) in program\Form1.cs:line 1750 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NatiThe program '[48096] program.exe: Managed (v2.0.50727)' has exited with code -1073741819 (0xc0000005) 'Access violation'. veWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadConte

    D 1 Reply Last reply
    0
    • T turbosupramk3

      I'm getting this error message on my laptop (win7 64bit/visual studio 2012 express), but not my desktop (win7 64bit/visual studio 2012 pro), code is unchanged. This is happening when my code runs through

      Quote:

      var versionPtr = GetPropellerVersion();

      Which is a dll import call via the code below, so it has something to do with the unmanaged code, but I'm a bit confused as to why? I believe the dll is 32 bit, so I've set the project to force x86, but I'm unsure as to what else could cause this? The project is set to 'copy always' the dll as well. I've also tried it in debug and release mode, same conflicting results. Does anyone have any ideas? Thanks for reading.

      Quote:

      [DllImport("Propellent.dll", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr GetPropellerVersion();

      Quote:

      Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at program.GetPropellerVersion() at program.btnDetectPort_Click(Object sender, EventArgs e) in program\Form1.cs:line 1750 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NatiThe program '[48096] program.exe: Managed (v2.0.50727)' has exited with code -1073741819 (0xc0000005) 'Access violation'. veWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadConte

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      OK, so what is "GetPropellerVersion"? What does the import look like? What does the function do? Got any docs on this thing?

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      T 2 Replies Last reply
      0
      • D Dave Kreskowiak

        OK, so what is "GetPropellerVersion"? What does the import look like? What does the function do? Got any docs on this thing?

        A guide to posting questions on CodeProject

        Click this: Asking questions is a skill. Seriously, do it.
        Dave Kreskowiak

        T Offline
        T Offline
        turbosupramk3
        wrote on last edited by
        #3

        Hi, I had to upload it from my machine, it's a pdf. If you're sketched out about downloading a random pdf, I copied the text below and pasted it in a code block, it's the same thing, just not as pretty as the pdf. http://temp-host.com/download.php?file=fv01pq[^] [code]

                                                                                                Parallax Propellent
        

        The Parallax Propellent software is a Windows-based tool for compiling and downloading to the Parallax Propeller chip. Propellent is available as both a library (Propellent.dll) and as an executable (Propellent.exe).
        ï‚·ï€ The Propellent Library (DLL) is for software developers to link into applications enabling immediate support of the Propeller using the same functions as the Parallax-made Propeller Tool development software.
        ï‚·ï€ The Propellent Executable (EXE) is a program that includes the Propellent Library within it and provides many of the same functions to anyone wishing for command-line support of the Propeller chip.

        This document is written for the Propellent Library. For details about the Propellent Executable, see the "Propellent Executable.pdf" document, or run the executable with the '/help' switch. For more information on the
        Parallax Propeller chip and tools, please visit http://www.parallax.com/propeller

        Features of the Propellent Library:
        ï‚·ï€ Can download Propeller Application images (.binary or .eeprom) to Propeller chips.
        ï‚·ï€ Can compile Propeller source (.spin) for downloading, for saving as a binary or eeprom image, for retrieval of source document, or just for syntax checking.
        ï‚·ï€ Can run with full, limited, or no visual feedback.
        ï‚·ï€ Includes the Propeller Tool's multi-threaded serial port handling and Propeller chip communication functionality.
        ï‚·ï€ Includes the Propeller Tool's dialogs for indicating serial port access and download progress as well as the user-customizable serial port search options.
        ï‚·ï€ Automatically stores user-modified preferences in the Windows Registry for use in future sessions. This can be disabled if desired.
        ï‚·ï€ Allows access to current list of available serial ports.
        ï‚·ï€ Allows calling application to view and/or specify preferences such as Library Path, Reset Signal (DTR, RTS, or both) and Serial Search Method (AUTO or specific port).
        ï‚·ï€

        D 1 Reply Last reply
        0
        • D Dave Kreskowiak

          OK, so what is "GetPropellerVersion"? What does the import look like? What does the function do? Got any docs on this thing?

          A guide to posting questions on CodeProject

          Click this: Asking questions is a skill. Seriously, do it.
          Dave Kreskowiak

          T Offline
          T Offline
          turbosupramk3
          wrote on last edited by
          #4

          It's returning the numeric values on the left and the code converts it to the text value on the right hand side of the = sign.

          112905168 = "COM6 : VERSION 1"

          81416960 = "COM6 : VERSION 1"

          How do those values equal the text? Are they memory addresses?

          D 1 Reply Last reply
          0
          • T turbosupramk3

            It's returning the numeric values on the left and the code converts it to the text value on the right hand side of the = sign.

            112905168 = "COM6 : VERSION 1"

            81416960 = "COM6 : VERSION 1"

            How do those values equal the text? Are they memory addresses?

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            No, it's not a memory address. It tells you in the documentation exactly what that value is.

            Quote:

            RETURN VALUE : Format is Bits 31 [to] 16 = port id, bits 15 [to] 0 = version

            It's single 32-bit value that returns 2 values. The 32-bits is divided into two fields. You've to do a bit of math to get the values separated.

            A guide to posting questions on CodeProject

            Click this: Asking questions is a skill. Seriously, do it.
            Dave Kreskowiak

            T 1 Reply Last reply
            0
            • T turbosupramk3

              Hi, I had to upload it from my machine, it's a pdf. If you're sketched out about downloading a random pdf, I copied the text below and pasted it in a code block, it's the same thing, just not as pretty as the pdf. http://temp-host.com/download.php?file=fv01pq[^] [code]

                                                                                                      Parallax Propellent
              

              The Parallax Propellent software is a Windows-based tool for compiling and downloading to the Parallax Propeller chip. Propellent is available as both a library (Propellent.dll) and as an executable (Propellent.exe).
              ï‚·ï€ The Propellent Library (DLL) is for software developers to link into applications enabling immediate support of the Propeller using the same functions as the Parallax-made Propeller Tool development software.
              ï‚·ï€ The Propellent Executable (EXE) is a program that includes the Propellent Library within it and provides many of the same functions to anyone wishing for command-line support of the Propeller chip.

              This document is written for the Propellent Library. For details about the Propellent Executable, see the "Propellent Executable.pdf" document, or run the executable with the '/help' switch. For more information on the
              Parallax Propeller chip and tools, please visit http://www.parallax.com/propeller

              Features of the Propellent Library:
              ï‚·ï€ Can download Propeller Application images (.binary or .eeprom) to Propeller chips.
              ï‚·ï€ Can compile Propeller source (.spin) for downloading, for saving as a binary or eeprom image, for retrieval of source document, or just for syntax checking.
              ï‚·ï€ Can run with full, limited, or no visual feedback.
              ï‚·ï€ Includes the Propeller Tool's multi-threaded serial port handling and Propeller chip communication functionality.
              ï‚·ï€ Includes the Propeller Tool's dialogs for indicating serial port access and download progress as well as the user-customizable serial port search options.
              ï‚·ï€ Automatically stores user-modified preferences in the Windows Registry for use in future sessions. This can be disabled if desired.
              ï‚·ï€ Allows access to current list of available serial ports.
              ï‚·ï€ Allows calling application to view and/or specify preferences such as Library Path, Reset Signal (DTR, RTS, or both) and Serial Search Method (AUTO or specific port).
              ï‚·ï€

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Does the error occur on the GetPropellerVersion line or the line after it? Using that return value as a pointer is going to be a bad thing 'cause it's not a memory address to a string.

              A guide to posting questions on CodeProject

              Click this: Asking questions is a skill. Seriously, do it.
              Dave Kreskowiak

              1 Reply Last reply
              0
              • D Dave Kreskowiak

                No, it's not a memory address. It tells you in the documentation exactly what that value is.

                Quote:

                RETURN VALUE : Format is Bits 31 [to] 16 = port id, bits 15 [to] 0 = version

                It's single 32-bit value that returns 2 values. The 32-bits is divided into two fields. You've to do a bit of math to get the values separated.

                A guide to posting questions on CodeProject

                Click this: Asking questions is a skill. Seriously, do it.
                Dave Kreskowiak

                T Offline
                T Offline
                turbosupramk3
                wrote on last edited by
                #7

                It fails on the var version = call propeller function line, but only on that one machine (so far). I read the documentation with the 2 words in the long, can you explain how they are converting the numeric value to text? I had it print out as binary and I still couldn't figure out how it was being converted?

                D 1 Reply Last reply
                0
                • T turbosupramk3

                  It fails on the var version = call propeller function line, but only on that one machine (so far). I read the documentation with the 2 words in the long, can you explain how they are converting the numeric value to text? I had it print out as binary and I still couldn't figure out how it was being converted?

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Where are you getting the text from?? NM. I just found in it in the code you originally posted. If it is an address, which your code seems to indicate it is, then the library is just storing a string and passing the address to you. But, if this really is the case, the documentation doesn't match what the library is doing and you should direct all further queries about this library to the people who wrote it.

                  A guide to posting questions on CodeProject

                  Click this: Asking questions is a skill. Seriously, do it.
                  Dave Kreskowiak

                  T 2 Replies Last reply
                  0
                  • D Dave Kreskowiak

                    Where are you getting the text from?? NM. I just found in it in the code you originally posted. If it is an address, which your code seems to indicate it is, then the library is just storing a string and passing the address to you. But, if this really is the case, the documentation doesn't match what the library is doing and you should direct all further queries about this library to the people who wrote it.

                    A guide to posting questions on CodeProject

                    Click this: Asking questions is a skill. Seriously, do it.
                    Dave Kreskowiak

                    T Offline
                    T Offline
                    turbosupramk3
                    wrote on last edited by
                    #9

                    Ok that confirms my confusion. There is another way to get the same value by using an int instead of a ptr (if I remember correctly), I will check my code and post that as well when I get home to see if heads or tails can be made of that.

                    1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      Where are you getting the text from?? NM. I just found in it in the code you originally posted. If it is an address, which your code seems to indicate it is, then the library is just storing a string and passing the address to you. But, if this really is the case, the documentation doesn't match what the library is doing and you should direct all further queries about this library to the people who wrote it.

                      A guide to posting questions on CodeProject

                      Click this: Asking questions is a skill. Seriously, do it.
                      Dave Kreskowiak

                      T Offline
                      T Offline
                      turbosupramk3
                      wrote on last edited by
                      #10

                      I'm not sure why this would behave differently on different win7 machines ... but calling the InitPropellent function in form1_load fixed this issue? Strange eh?

                      InitPropellent((long)this.Handle, false, "");

                      D 1 Reply Last reply
                      0
                      • T turbosupramk3

                        I'm not sure why this would behave differently on different win7 machines ... but calling the InitPropellent function in form1_load fixed this issue? Strange eh?

                        InitPropellent((long)this.Handle, false, "");

                        D Offline
                        D Offline
                        Dave Kreskowiak
                        wrote on last edited by
                        #11

                        No, not strange. You just converted the Handle value to a 64-bit integer. This tells me that your other machine where it works is a 32-bit machine and your Win7 machine is 64-bit.

                        A guide to posting questions on CodeProject

                        Click this: Asking questions is a skill. Seriously, do it.
                        Dave Kreskowiak

                        T 1 Reply Last reply
                        0
                        • D Dave Kreskowiak

                          No, not strange. You just converted the Handle value to a 64-bit integer. This tells me that your other machine where it works is a 32-bit machine and your Win7 machine is 64-bit.

                          A guide to posting questions on CodeProject

                          Click this: Asking questions is a skill. Seriously, do it.
                          Dave Kreskowiak

                          T Offline
                          T Offline
                          turbosupramk3
                          wrote on last edited by
                          #12

                          Both machines are actually 64 bit, although I have the project set to compile to 32 bit output since the dll is 32 bit.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups