i Get System.AccessViolationException was unhandled

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Trupti Panchal
    New Member
    • Mar 2013
    • 5

    i Get System.AccessViolationException was unhandled

    Hi,

    My C# app throws the following exception:

    System.AccessVi olationExceptio n: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Code:
    static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);          
                Application.Run(new Login());  // get exception at this line(wen i try to enter details in text box)        
               
            }
    The stack trace is as follows :
    " at System.Windows. Forms.UnsafeNat iveMethods.Call WindowProc(IntP tr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n at System.Windows. Forms.NativeWin dow.DefWndProc( Message& m)\r\n at System.Windows. Forms.Control.W ndProc(Message& m)\r\n at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)\r\n at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)\r\n at System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32 reason, ApplicationCont ext context)\r\n at System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason, ApplicationCont ext context)\r\n at WindowsFormsApp lication1.Progr am.Main() in D:\\TRUPTI\\02-02-2013-RNSB WithPaymentEdit \\RNSB\\RNSB\\P rogram.cs:line 25\r\n at System.AppDomai n._nExecuteAsse mbly(Assembly assembly, String[] args)\r\n at Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()\r\n at System.Threadin g.ExecutionCont ext.Run(Executi onContext executionContex t, ContextCallback callback, Object state)\r\n at System.Threadin g.ThreadHelper. ThreadStart()"
    Last edited by Rabbit; Mar 20 '13, 04:31 PM. Reason: Please use code tags when posting code.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    This is a difficult one to be honest. Possibilities are

    1.) Some unmanaged (perhaps non C#) code is causing this and you might be only getting this in development and not in production. Doing Tools menu ->Options -> Debugging -> General -> and unchecking the option "Suppress JIT optimization on module load" might make it disappear from your dev environment. If you are in control of the unmanaged code invocations try disabling some of them to see if you can pin point the one that is problematic.


    2.) It could be that there are some components that you not disposing of properly

    3.) You could be using .NET 2.0 which has a bug that was fixed with this patch http://support.microsoft.com/kb/971030

    Comment

    • Trupti Panchal
      New Member
      • Mar 2013
      • 5

      #3
      can u suggest any other fix to this problem. i tried the first one. it didn't work out .

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Did you check for 2 and 3 then?

        Comment

        • Trupti Panchal
          New Member
          • Mar 2013
          • 5

          #5
          yes . i did try the 2nd and 3rd options.. i also tried to run this project in another PC. its runs perfectly fine. so according to my knowledge there is no issues with coding. i m not able to figure out the where the problem lies..

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Are the different PCs that you tried the same .NET versions and OS as the PC where it fails?

            Comment

            • Trupti Panchal
              New Member
              • Mar 2013
              • 5

              #7
              yes... same .net frame work is installed. In my PC OS is windows 7 ultimate, and in the other its windows 7 enterprise.

              Comment

              • Trupti Panchal
                New Member
                • Mar 2013
                • 5

                #8
                Problem solved. the project bus built on 32 bit operating system and i was trying to run on 64 bit operating system.
                Goto configuration manager platform select the appropriate platform

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Thanks for posting back your solution.

                  Comment

                  Working...