1

我正在使用 FWTools 和 SharpMap(带有 gdal_sharp)来构建应用程序。我有一个奇怪的错误。加载栅格图层在调试模式下运行良好,但在发布时调用时在构造函数中的 SharpMap.Layers.GdalRasterLayer 中引发异常

 _projectionWkt = _gdalDataset.GetProjectionRef();

完整的例外是:

{System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at OSGeo.GDAL.GdalPINVOKE.Dataset_GetProjectionRef(HandleRef jarg1)
   at OSGeo.GDAL.Dataset.GetProjectionRef()
   at SharpMap.Layers.GdalRasterLayer..ctor(String strLayerName, String imageFilename) in d:\Fakultet\IX Semestar\GIS\Projekat\GreenGIS\SharpMap.Extensions\Layers\GdalRasterLayer.cs:line 404
   at GreenGIS.Form1.addRasterLayer() in d:\Fakultet\IX Semestar\GIS\Projekat\GreenGIS\GreenGIS\Form1.cs:line 50
   at GreenGIS.Form1.toolStripButtonAddVector_Click(Object sender, EventArgs e) in d:\Fakultet\IX Semestar\GIS\Projekat\GreenGIS\GreenGIS\Form1.cs:line 129
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.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.Callback(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(IntPtr 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 GreenGIS.Program.Main() in d:\Fakultet\IX Semestar\GIS\Projekat\GreenGIS\GreenGIS\Program.cs:line 19}

奇怪的是,在 Debug 中一切正常。构建设置是准确的,包括 .Net 4.0、x86 平台。

有任何想法吗?

先感谢您

4

2 回答 2

1

我遇到了类似的问题,但是在使用来自http://www.gisinternals.com/sdk/的当前编译的二进制文件后,问题得到了解决。我在http://vipassanaandenvironmentalinformatics.blogspot.co.nz/2013/03/getting-started-with-c-and-gdal.html记录了对我有用的步骤。

希望这个答案仍然对其他人有所帮助。

于 2013-03-19T22:23:16.493 回答
0

这似乎是 Windows 8 的问题,它是 DEP 实现以及 .Net 4.0。我在包装器中使用了 C++ dll,操作系统不允许它执行。它可以通过编辑 DLL 或关闭数据执行保护来解决。

于 2013-01-27T00:52:27.677 回答