开发者

Attempted to read or write protected memory. - After converting app from VS 2005 to VS 2008

I have an application that was written in VS 2005 (C#). Works fine, it calls a 3rd Party dll. Now that I've converted it to VS 2008 (using the wizard), I get the following error when trying to instantiate the 3rd party dll.

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Not sure where to even start debugging this. Can anyone point me in the right direction?

EDIT: As a side note it does the exact same thing under VS 2010.

EDIT: Both VS 2005 and VS 2008 projects using the same code target .NET 2.0 Framework

EDIt: It's an ActiveX library called LPDFCTRLLib. I've simply added it under References and create a new instance of it:

public LPDFCTRLLib.LPDFWndClass olpdf = null;
//and later in my code
//...
//this is where it fails
olpdf = new LPDFCTRLLib.LPDFWndClass();

EDIT: Stack Trace

at pcl2pdf.Form1.convertPCL(String inputFile, String outputFile) in C:\junk\pcl2pdf\pcl2pdf\pcl2pdf\Form1.cs:line 29
   at pcl2pdf.Form1.Form1_Load(Object sender, EventArgs e) in C:\junk\pcl2pdf\pcl2pdf\pcl2pdf\Form1.cs:line 24
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.F开发者_开发知识库orm.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.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   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 pcl2pdf.Program.Main() in C:\junk\pcl2pdf\pcl2pdf\pcl2pdf\Program.cs:line 17
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()


You should rempve the DLL and then re-Add it. Especially for an unmanaged DLL. And check with the supplier if it is compatible.

And please note: You do not convert Projects to a VS version, except maybe for the config file. You make it target a Framework version. Your question lacks all info about Fx versions.


Here is the same problem described: http://bloggingabout.net/blogs/dennis/archive/2009/06/08/attempted-to-read-or-write-protected-memory-in-a-net-application.aspx

"Anyway, the solution was to enable JIT optimization. In other words, in Visual Studio 2008 choose “Tools” and then “Options”. Select “Debugging” and “General” and find the line that says “Suppress JIT optimization on module load”. This kind of makes sure that the debugger and the JIT compiled code aren’t running out of sync because the JIT compiler is such a super duper optimizer of your code. This did the trick."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜