C#调用haskell遭遇Attempted to read or write protected memory
1. Haskell的代码如下:

上面的代码中readMarkdown与writeHtmlString是pandoc中的函数,newString的作用是将String转换为IO CString。
2. C语言的代码如下:

上面的代码是dll的调用入口。
3. ghc编译出来的头文件如下:

4. C#调用代码如下:
class Native
{
[DllImport("libpandoc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern IntPtr markdownToHtml(byte[] markdown);
} public class Processor
{
public string Process(string text)
{
var intPtr = Native.markdownToHtml(System.Text.Encoding.UTF8.GetBytes(text));
var html = Marshal.PtrToStringAnsi(intPtr);
return html;
}
}
5. 运行C#代码之后,出现错误:
An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
对应的中文错误信息:
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
6. 而在ghci中执行直接执行haskell代码能得到正确的结果:

被这个“Attempted to read or write protected memory. ”问题困扰了很长时间,一直未找到解决方法。
【更新】
后来找到了解决方法,详见:困扰多日的C#调用Haskell问题竟然是Windows的一个坑
C#调用haskell遭遇Attempted to read or write protected memory的更多相关文章
- c# 传递Null的string值导致的调用C++的dll报错 Attempted to read or write protected memory.
c# 调用C++的dll报错 Attempted to read or write protected memory: 原因是:c# 传递Null的string值导致的,将Null改为string ...
- System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt".
昨天遇到一个比较奇怪的问题,运行VS2010调试程序的时候,总是会报一个错,然后程序就挂掉了:无可用源….,弹出一个窗口提示:System.AccessViolationException: Atte ...
- [SQL] - Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 问题之解决
场景: 使用 Oracle.DataAccess.dll 访问数据库时,OracleDataAdapter 执行失败. 异常: System.AccessViolationException was ...
- 困扰多日的C#调用Haskell问题竟然是Windows的一个坑
最近一直被C#调用Haskell时的“尝试读取或写入受保护的内存”问题所困扰(详见C#调用haskell遭遇Attempted to read or write protected memory,C# ...
- 经过实际验证的C#调用Haskell的方法
[系统环境] Windows Server 2008 R2,Haskell Platform 2013.2.0.0,ghc 7.6.3,cabal 1.16.0 [操作步骤] 1. 安装Windows ...
- System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
系统debug时出现错误,System.AccessViolationException: 尝试读取或写入受保护的内存.这通常指示其他内存已损坏. Attempted to read or write ...
- 要让CLR挂掉的话……
http://rednaxelafx.iteye.com/blog/460893 (Disclaimer:如果需要转载请先与我联系. 作者:RednaxelaFX -> rednaxelafx. ...
- 背水一战 Windows 10 (52) - 控件(集合类): ItemsControl - 自定义 ItemsControl, 自定义 ContentPresenter
[源码下载] 背水一战 Windows 10 (52) - 控件(集合类): ItemsControl - 自定义 ItemsControl, 自定义 ContentPresenter 作者:weba ...
- WinDbg 解决Font.ToLogFont AccessViolationExcetion
有个程序总是在windows 2003 server 异常退出. 并且, 查看调用栈也肯奇怪, 应该是很正常的调用. 怀疑是堆溢出. 开启heap trace : C:\Program Files\ ...
随机推荐
- ios微信打开网页键盘弹起后页面上滑,导致弹框里的按钮响应区域错位
input失去焦点,页面被顶起没有还原,所以就有以下的方法来处理 $("input").blur(function(){ setTimeout(() => { co ...
- keepalived配虚拟ip(vip)的作用
keepalived是以VRRP协议为实现基础的,VRRP全称Virtual Router Redundancy Protocol,即虚拟路由冗余协议. 虚拟路由冗余协议,可以认为是实现路由器高可用的 ...
- 如何获取堆的dump 的信息,如何分析
获取方式: 1. jdk 自带启动参数 -XX:+HeapDumpBeforeFullGC -XX:HeapDumpPath=/x/x 产生dump日志,然后用visualVm分析 2. jmap 命 ...
- hbase 无法打开60010网页
在hbase-site.xml中添加如下节点 <property> <name>hbase.master.info.port</name> <value> ...
- 带token的get和post方法
GET和POST传值失败,多半是传输的字符串和URL的事 public static string ExcuteGetToken(string serviceUrl, string ReqInfo, ...
- .net写本地文件的一个方法
整理代码,.net在本地写html文件的一个方法,代码如下 public static void WriteFile(string FilePath, string FileInfo, string ...
- http://itellyou.cn/
http://itellyou.cn/ 这里提供了微软MSDN上所有能下载的软件. 下载完记得检验. 这是更详细的介绍:http://wenku.baidu.com/link?url=_dZ0mYvl ...
- vue2.0 移动端,下拉刷新,上拉加载更多插件 转:
转自:http://www.cnblogs.com/gmajip/p/7204072.html <template lang="html"> <div class ...
- docker 加速器配置目录
centos 7 : /lib/systemd/system/docker.service
- 使用Hadoop API 解压缩 HDFS文件
接上篇:使用Hadoop API 压缩HDFS文件 压缩完了,当然需要解压缩了. 直接上代码: private static void getFile(String filePath) throws ...