Click here to Skip to main content
15,896,201 members
Home / Discussions / C#
   

C#

 
AnswerRe: Can I write my own XBox 360 program? Pin
OriginalGriff2-Jan-15 5:00
mveOriginalGriff2-Jan-15 5:00 
GeneralRe: Can I write my own XBox 360 program? Pin
trantrum2-Jan-15 5:07
professionaltrantrum2-Jan-15 5:07 
GeneralRe: Can I write my own XBox 360 program? Pin
OriginalGriff2-Jan-15 5:13
mveOriginalGriff2-Jan-15 5:13 
GeneralRe: Can I write my own XBox 360 program? Pin
trantrum2-Jan-15 5:21
professionaltrantrum2-Jan-15 5:21 
GeneralRe: Can I write my own XBox 360 program? Pin
OriginalGriff2-Jan-15 5:25
mveOriginalGriff2-Jan-15 5:25 
AnswerRe: Can I write my own XBox 360 program? Pin
BillWoodruff2-Jan-15 6:56
professionalBillWoodruff2-Jan-15 6:56 
GeneralRe: Can I write my own XBox 360 program? Pin
trantrum2-Jan-15 9:20
professionaltrantrum2-Jan-15 9:20 
QuestionUnhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 4:28
turbosupramk32-Jan-15 4:28 
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.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at program.Program.Main() in program\Program.cs:line 19



C#
private void btnDetectPort_Click(object sender, EventArgs e)
        {
            cbxSerialPort.Items.Clear();
            string[] ports = SerialPort.GetPortNames();
            foreach (string port in ports)
            {
                cbxSerialPort.Items.Add(port);
                cbxSerialPort.SelectedIndex = 0;
                serialPort1.PortName = port;
                serialPort1.BaudRate = 115200;
                serialPort1.Encoding = Encoding.ASCII;

                try
                {
                    serialPort1.Open();
                    this.Invoke(new EventHandler(delegate
                    {
                        serialPort1.Close();
                    }));
                }
                catch (Exception)
                {
                   // do nothing
                }

            }

            var versionPtr = GetPropellerVersion();                     // error here
            string version = Marshal.PtrToStringAnsi(versionPtr);       

            int delimiter = version.IndexOf(':');
            if (delimiter > -1)
            {
                string comPort = version.Remove(delimiter - 1);
                string firmWare = version.Remove(0, delimiter + 2);
                tbxPropPortFound.Text = comPort;
                                int comPortIndex = cbxSerialPort.FindString(comPort);
                cbxSerialPort.SelectedIndex = comPortIndex;
            }
        }

AnswerRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 4:35
mveDave Kreskowiak2-Jan-15 4:35 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 5:07
turbosupramk32-Jan-15 5:07 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 8:39
mveDave Kreskowiak2-Jan-15 8:39 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 6:29
turbosupramk32-Jan-15 6:29 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 8:38
mveDave Kreskowiak2-Jan-15 8:38 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 8:46
turbosupramk32-Jan-15 8:46 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 8:49
mveDave Kreskowiak2-Jan-15 8:49 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 11:10
turbosupramk32-Jan-15 11:10 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk33-Jan-15 19:13
turbosupramk33-Jan-15 19:13 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak4-Jan-15 4:30
mveDave Kreskowiak4-Jan-15 4:30 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk34-Jan-15 6:34
turbosupramk34-Jan-15 6:34 
Questionarray property Pin
TMattC1-Jan-15 5:13
TMattC1-Jan-15 5:13 
AnswerRe: array property Pin
Thomas Daniels1-Jan-15 5:29
mentorThomas Daniels1-Jan-15 5:29 
GeneralRe: array property Pin
PIEBALDconsult1-Jan-15 5:47
mvePIEBALDconsult1-Jan-15 5:47 
AnswerRe: array property Pin
OriginalGriff1-Jan-15 6:07
mveOriginalGriff1-Jan-15 6:07 
GeneralRe: array property Pin
harold aptroot1-Jan-15 6:16
harold aptroot1-Jan-15 6:16 
AnswerRe: array property Pin
BillWoodruff1-Jan-15 9:23
professionalBillWoodruff1-Jan-15 9:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.