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\ ...
随机推荐
- centos7中输入ifconfig出现ens33,没有eth0(转)
vmware安装的centos7中没有出现eth0网卡,也没有ip,不能上网,输入ifconfig后如下图 解决办法 1.编辑网卡的配置文件 vi /etc/sysconfig/network-scr ...
- tp5安装验证码
- Using The jQuery Migrate Plugin
jQuery( html [, ownerDocument ] )Returns: jQuery Description: Creates DOM elements on the fly from t ...
- 论坛:设计实体-->分析功能-->实现功能 之 《分析功能》
其中 管理文章 的功能没有做,以下做的设计 浏览与参与 功能的步骤 分析功能 5个功能. 7个请求. 实现功能 Action, 7个方法 Service Dao Jsp For ...
- CRC标准以及简记式
一.CRC标准 下表中列出了一些见于标准的CRC资料: 名称 生成多项式 简记式* 应用举例 CRC-4 x4+x+1 3 ITU G.704 CRC-8 x8+x5+x4+1 31 DS18B20 ...
- [Oracle]ORA-14400:插入的分区关键字未映射到任何分区
今天在使用测试库的时候发生ORA-14400:inserted partition key does not map to any partition 解决过程: 经过百度,发现出现ORA-14400 ...
- MySQL open_files_limit相关设置
背景: 数据库链接不上,报错: root@localhost:/var/log/mysql# mysql -uzjy -p -h192.168.1.111 --default-charact ...
- org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403
爬取网站的时候 conn = Jsoup.connect(url).timeout(5000).get();直接用get方法,有些网站可以正常爬取. 但是有些网站报403错误,403是一种在网站访问的 ...
- 2018.12.30 poj3734 Blocks(生成函数)
传送门 生成函数入门题. 按照题意构造函数: 对于限定必须是出现偶数次的颜色:1+x22!+x44!+...=ex+e−x21+\frac {x^2}{2!}+\frac {x^4}{4!}+...= ...
- 2018.10.29 bzoj4564: [Haoi2016]地图(仙人掌+莫队)
传送门 根据原图建一棵新的树. 把原图每一个环上除了深度最浅的点以外的点全部向深度最浅的点连边. 然后可以搞出来一个dfsdfsdfs. 这个时候我们就成功把问题转换成了对子树的询问. 然后就可以对权 ...