我创造了一个关于测试文件MbnApi.dll程序,这是我的代码:System.AccessViolationException:试图读取或写入受保护的内存。使用MbnApi.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MbnApi;
namespace TestMbnApi
{
class Program
{
static void Main(string[] args)
{
MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
IMbnInterfaceManager infMgr = mbnInfMgr as IMbnInterfaceManager;
IMbnConnectionManager conManager = (IMbnConnectionManager)new MbnConnectionManager();
// Connection
IMbnConnection[] connections = conManager.GetConnections();
IMbnConnection con = connections.First();
// Get interfaceID
String interfaceID = con.InterfaceID;
Console.WriteLine("InterfaceID : {0}", interfaceID);
// Get interface
IMbnInterface interfa = infMgr.GetInterface(interfaceID) as IMbnInterface;
// GetInterfaceCapability
MBN_INTERFACE_CAPS caps = interfa.GetInterfaceCapability();
Console.WriteLine("Caps :{0}", caps);
Console.ReadLine();
}
}
}
当我建立到文件.exe和笔记本电脑Windows上运行10 &有SIM卡3G。
Unhandled exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.StubHelpers.ValueClassMarshaler.ConvertToManaged(IntPtr dst, IntPtr src, IntPtr pMT)
at MbnApi.IMbnInterface.GetInterfaceCapability()
at TestMbnApi.Program.Main(String[] args)
我使用Frameword 4.6.1的.Net和Visual Studio 2015年社区版本有:然后我接到错误。我不明白为什么这个程序错误?有没有人可以支持我这件事。 谢谢大家!
错误发生在哪里?你有没有尝试捕捉异常? –
如果我想访问'IMbnInterface'的属性,比如'GetHomeProvider',我有同样的问题。你解决了你的问题吗? – creg
我很高兴你找到了解决方案,但请在发布之前先研究一下问题。还有一件事,'MbiApi'不适用于所有人,因此这段代码不会编译。如果您使用特殊API继续前进,请提供其他人下载的链接。另外,3G sim与代码有什么关系。好的信息应该是OS + 64或32位。示例Win-x86或Win-x64。 –