The "try to read or write protected memory" issue when C # calls Haskell

Source: Internet
Author: User

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;
    } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.