c# 读取或写入受保护的内存 异常

问题描述

c# 读取或写入受保护的内存 异常

做的一个地图程序,程序集是其他公司提供的,当往地图里面有大概10000左右的点的时候 ,就会出现如下的错误
异常信息如下
未处理 System.AccessViolationException
Message=尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
Source=Microsoft.DirectX.Direct3D
StackTrace:
在 Microsoft.DirectX.Direct3D.Device.DrawIndexedUserPrimitives(PrimitiveType primitiveType, Int32 minVertexIndex, Int32 numVertexIndices, Int32 primitiveCount, Object indexData, Boolean sixteenBitIndices, Object vertexStreamZeroData)
在 TKsoft.Earth.LineStringRender.Render(DrawArgs e) 位置 E:Object地图demoEarth2.5RenderableNewLayerLineStringRender.cs:行号 242
在 TKsoft.Earth.RenderableList`1.Render(DrawArgs drawArgs) 位置 E:Object地图demoEarth2.5RenderableRenderableListT.cs:行号 107
在 TKsoft.Earth.WorldWindows.Render() 位置 E:Object地图demoEarth2.5WorldWindowsWorldWindows.cs:行号 464
在 TKsoft.Earth.WorldWindows.Application_Idle(Object sender, EventArgs e) 位置 E:Object地图demoEarth2.5WorldWindowsWorldWindows.cs:行号 846
在 System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 AreaRadioMonitoringTest.Program.Main() 位置 E:Object海域无线1DevelopLibrary2SourceCodeAreaRadioMonitoringTestProgram.cs:行号 18
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
请问各位大神,出现这个异常主要有什么原因!!

解决方案

不正确地调用api,错误发生在mainform的构造函数中,不在这里。

解决方案二:

当往地图里面有大概10000左右的点的时候 ,就会出现如下的错误

教你一个调试技巧, 在可能出现异常的代码前设置断点,然后运行调试,直接运行。到了发生异常的地方会自动捕捉异常的。到时候你就看到准确的错误了。

解决方案三:

我的异常-VS2012“System.AccessViolationException: 尝试读取或写入受保护的内存。”

时间: 2024-07-29 01:04:41

c# 读取或写入受保护的内存 异常的相关文章

C#调用Haskell时的“尝试读取或写入受保护的内存”问题

最近一直被C#调用Haskell时的"尝试读取或写入受保护的内存"问题所困扰(详见C#调用haskell遭遇Attempted to read or write protected memory,C#调用haskell时的"尝试读取或写入受保护的内存"问题),而且困在其中,越陷超深,无法自拔,差点弃用C#解决我们面临的问题. 问题是这样的,只要在Haskell代码中对字符串进行操作,在C#调用时就会引发异常: An unhandled exception of ty

dll c#-c#调用c++的dll出现尝试读取或写入受保护的内存问题

问题描述 c#调用c++的dll出现尝试读取或写入受保护的内存问题 使用c#调用c++的一个dll.c++的接口函数为: extern "C" __declspec(dllexport)bool __stdcall CreateDetmObject(IDetManager **ppDetManager); 参数IDetManager为一个结构体: struct IDetManager { virtual void __stdcall SetListener(HWND hWnd) = 0

c#尝试读取或写入受保护的内存。这通常指示其他内存已损坏 怎么解决

问题描述 ///<summary>///byte数组转结构///</summary>///<paramname="bytes">byte数组</param>///<paramname="type">结构类型</param>///<returns>转换后的结构</returns>publicstaticobjectBytesToStruct(byte[]bytes,Type

方法-尝试读取或写入受保护的内存。这通常指示其他内存已损坏

问题描述 尝试读取或写入受保护的内存.这通常指示其他内存已损坏 c#调用别人的dll里面的方法出现""尝试读取或写入受保护的内存.这通常指示其他内存已损坏.""!纠结了好久!请大家帮帮我吧 解决方案 如果是调用的非托管dll,则需要这样调用.http://www.cnblogs.com/Charles2008/archive/2010/01/10/1643449.html http://www.cnblogs.com/xugang/archive/2007/12/2

c++-C# 调用C++ dll是出现这样的错误“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

问题描述 C# 调用C++ dll是出现这样的错误"尝试读取或写入受保护的内存.这通常指示其他内存已损坏. 调试时是这样的: SDK上是这样说明的: 我调用这个dll时是这样的: 困扰了很久,希望有大神来看一看,感激不敬 解决方案 C#尝试读取或写入受保护的内存.这通常指示其他内存已损坏.C# 尝试读取或写入受保护的内存 .这通常指示其他内存已损坏.C#尝试读取或写入受保护的内存.这通常指示其他内存已损坏. 解决方案二: 先看是不是你的参数有问题,然后就是数据对不对 解决方案三: 是不是重复调用

c#调c++dll,尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

问题描述 调用时尝试读取或写入受保护的内存.这通常指示其他内存已损坏.不知道是什么情况,网上好多都是c++Long对应c#int,但是我已经转了还是没用,这代码一开始时可以用的,我重装了win7系统后就运行不了了....求大神帮忙c++:extern"C"__declspec(dllexport)BOOL__stdcallTCR_OpenReader(longnPort){if(1==g_iProtocol){g_CardReader.CreateInterface("1.d

求助,C#调用C++dll时提示:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

问题描述 C++dll的头文件接口描述如下:#pragmapack(push,1)typedefstructXCtrlStatus{XCtrlStatus(unsignedlongV=0){*reinterpret_cast<unsignedlong*>(this)=V;}unsignedcharERR:1;unsignedcharAUTO:1;unsignedcharRUN:2;unsignedcharDIR:2;unsignedchar:1;unsignedchar:1;unsignedc

winform-C# Winform项目中, 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

问题描述 C# Winform项目中, 尝试读取或写入受保护的内存.这通常指示其他内存已损坏. C/C++ 代码,这个是第三方提供的外部方法(调用"华大HD-900身份证阅读器接口函数"):int HD_Read_BaseInfo(char* pBmpData char *pName char *pSex char *pNation char *pBirth char *pAddress char *pCertNo char *pDepartment char *pEffectData

读取PLC中的结构体时,总是提示:尝试读取或写入受保护的内存。这通常指示其他内存已损坏

问题描述 读取PLC中的结构体时,总是提示:尝试读取或写入受保护的内存.这通常指示其他内存已损坏,但是,我把string[]改成char[]时,可以读到300个单字符,是数据类型的问题么?usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Wi