Has been plagued by the "attempt to read or write protected memory" issue when C # was called Haskell (see the C # call Haskell encounter attempted to read or write protected memory,c# when invoking Haskell). Attempt to read or write protected memory "problem", and trapped in it, the more deep, unable to extricate themselves, almost abandoned with C # to solve the problems we face.
The problem is that, as long as the string is manipulated in the Haskell code, an exception is thrown when the C # call is made:
An unhandled exception of type ' system.accessviolationexception ' occurred in Unknown Module.
Additional information:attempted to read or write protected memory. This is often a indication that the other memory is corrupt.
The example Haskell code is as follows:
If you return a string directly, everything works, and the example Haskell code is as follows:
C # invokes sample code:
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;
}