Desperate Need Of Help "Attempted To Read Or Write Protected Memory"

Discussion in 'ASP .Net' started by humbleaptience, Sep 7, 2006.

  1. I have a web application that uses a DLL using DLLImport.

    Twice I have put the application live on the net and it has been used
    hundreds or thousands of time before it has been strangely brought
    down.

    System.AccessViolationException: Attempted to read or write protected
    memory. This is often an indication that other memory is corrupt. at
    ProjApi.Proj.pj_init_plus(String pjstr) at coordinate.LLtoUTM(Int32
    datumIn, Int32 datumOut, Double p_lat, Double p_lon, Double&
    UTMNorthing, Double& UTMEasting, Int32& UTMZone) at
    coordinate.LLtoUTMZone(Double lat, Double lon, Int32 datumIn, Int32
    datumOut, Int32& z, Double& n, Double& e) at
    getfactory.Page_Load(Object sender, EventArgs e) at
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
    Object t, EventArgs e) at
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
    EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at
    System.Web.UI.Control.LoadRecursive() at
    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    Here is my code that calls the extern method

    public static int LLtoUTM(int datumIn, int datumOut, double p_lat,
    double p_lon,ref double UTMNorthing,ref double UTMEasting,ref int
    UTMZone)
    {
    int errno = 0;
    //This is the formula for calculating which Zone a point is in at a
    particular lat/long
    int ZoneNumber = Convert.ToInt32(Math.Floor((p_lon + 180) / 6)) + 1;
    double[] x = new double[1];
    double[] y = new double[1];
    double[] z = new double[1];
    y[0] = p_lat * ProjApi.Proj.DEG_TO_RAD;
    x[0] = p_lon * ProjApi.Proj.DEG_TO_RAD;
    z[0] = 0.0;
    IntPtr src0 = ProjApi.Proj.pj_init_plus("+proj=latlong
    +datum=NAD27");
    IntPtr src1 = ProjApi.Proj.pj_init_plus("+proj=latlong
    +datum=NAD83");
    IntPtr dst0 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
    + ZoneNumber + " +datum=NAD27");
    IntPtr dst1 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
    + ZoneNumber + " +datum=NAD83");
    //This nice little bit of code below is designed to execute
    pj_transfrom (the proj lib all around function)
    //with the correct parameters so that a datumshift to the correct
    datum is included.
    try
    {
    if (datumIn == 0)
    {
    if (datumOut == 0)
    {
    errno = ProjApi.Proj.pj_transform(src0, dst0,
    1, 1, x, y, z);//NAD27-NAD83
    }
    else
    {
    errno = ProjApi.Proj.pj_transform(src0, dst1,
    1, 1, x, y, z);//NAD27-NAD27
    }
    }
    else
    {
    if (datumOut == 0)
    {
    errno = ProjApi.Proj.pj_transform(src1, dst0,
    1, 1, x, y, z);//NAD83-NAD27
    }
    else
    {
    errno = ProjApi.Proj.pj_transform(src1, dst1,
    1, 1, x, y, z);//NAD83-NAD83
    }
    }
    }
    catch { }

    ProjApi.Proj.pj_free(dst1);
    ProjApi.Proj.pj_free(src1);
    ProjApi.Proj.pj_free(dst0);
    ProjApi.Proj.pj_free(src0);
    UTMNorthing = y[0];
    UTMEasting = x[0];
    UTMZone = ZoneNumber;
    return errno;
    }


    Here is the definition and DLL import.
    [DllImport("proj.dll", CharSet = CharSet.Ansi,
    CallingConvention = CallingConvention.Cdecl)]
    public static extern unsafe int pj_transform(IntPtr src, IntPtr
    dst,
    int point_count, int point_offset,
    [InAttribute, OutAttribute] double[] x,
    [InAttribute, OutAttribute] double[] y,
    [InAttribute, OutAttribute] double[] z);

    Any help at all would be useful. I am not able to trigger this error
    myself so I can't even do trial and error.
    humbleaptience, Sep 7, 2006
    #1
    1. Advertising

  2. humbleaptience

    Winista Guest

    Did you develop unmanaged proj.dll? Do you source for that DLL?
    That code seems to be causing some meory overwrite.

    "humbleaptience" <> wrote in message
    news:...
    >I have a web application that uses a DLL using DLLImport.
    >
    > Twice I have put the application live on the net and it has been used
    > hundreds or thousands of time before it has been strangely brought
    > down.
    >
    > System.AccessViolationException: Attempted to read or write protected
    > memory. This is often an indication that other memory is corrupt. at
    > ProjApi.Proj.pj_init_plus(String pjstr) at coordinate.LLtoUTM(Int32
    > datumIn, Int32 datumOut, Double p_lat, Double p_lon, Double&
    > UTMNorthing, Double& UTMEasting, Int32& UTMZone) at
    > coordinate.LLtoUTMZone(Double lat, Double lon, Int32 datumIn, Int32
    > datumOut, Int32& z, Double& n, Double& e) at
    > getfactory.Page_Load(Object sender, EventArgs e) at
    > System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
    > Object t, EventArgs e) at
    > System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
    > EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at
    > System.Web.UI.Control.LoadRecursive() at
    > System.Web.UI.Page.ProcessRequestMain(Boolean
    > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    >
    > Here is my code that calls the extern method
    >
    > public static int LLtoUTM(int datumIn, int datumOut, double p_lat,
    > double p_lon,ref double UTMNorthing,ref double UTMEasting,ref int
    > UTMZone)
    > {
    > int errno = 0;
    > //This is the formula for calculating which Zone a point is in at a
    > particular lat/long
    > int ZoneNumber = Convert.ToInt32(Math.Floor((p_lon + 180) / 6)) + 1;
    > double[] x = new double[1];
    > double[] y = new double[1];
    > double[] z = new double[1];
    > y[0] = p_lat * ProjApi.Proj.DEG_TO_RAD;
    > x[0] = p_lon * ProjApi.Proj.DEG_TO_RAD;
    > z[0] = 0.0;
    > IntPtr src0 = ProjApi.Proj.pj_init_plus("+proj=latlong
    > +datum=NAD27");
    > IntPtr src1 = ProjApi.Proj.pj_init_plus("+proj=latlong
    > +datum=NAD83");
    > IntPtr dst0 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
    > + ZoneNumber + " +datum=NAD27");
    > IntPtr dst1 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
    > + ZoneNumber + " +datum=NAD83");
    > //This nice little bit of code below is designed to execute
    > pj_transfrom (the proj lib all around function)
    > //with the correct parameters so that a datumshift to the correct
    > datum is included.
    > try
    > {
    > if (datumIn == 0)
    > {
    > if (datumOut == 0)
    > {
    > errno = ProjApi.Proj.pj_transform(src0, dst0,
    > 1, 1, x, y, z);//NAD27-NAD83
    > }
    > else
    > {
    > errno = ProjApi.Proj.pj_transform(src0, dst1,
    > 1, 1, x, y, z);//NAD27-NAD27
    > }
    > }
    > else
    > {
    > if (datumOut == 0)
    > {
    > errno = ProjApi.Proj.pj_transform(src1, dst0,
    > 1, 1, x, y, z);//NAD83-NAD27
    > }
    > else
    > {
    > errno = ProjApi.Proj.pj_transform(src1, dst1,
    > 1, 1, x, y, z);//NAD83-NAD83
    > }
    > }
    > }
    > catch { }
    >
    > ProjApi.Proj.pj_free(dst1);
    > ProjApi.Proj.pj_free(src1);
    > ProjApi.Proj.pj_free(dst0);
    > ProjApi.Proj.pj_free(src0);
    > UTMNorthing = y[0];
    > UTMEasting = x[0];
    > UTMZone = ZoneNumber;
    > return errno;
    > }
    >
    >
    > Here is the definition and DLL import.
    > [DllImport("proj.dll", CharSet = CharSet.Ansi,
    > CallingConvention = CallingConvention.Cdecl)]
    > public static extern unsafe int pj_transform(IntPtr src, IntPtr
    > dst,
    > int point_count, int point_offset,
    > [InAttribute, OutAttribute] double[] x,
    > [InAttribute, OutAttribute] double[] y,
    > [InAttribute, OutAttribute] double[] z);
    >
    > Any help at all would be useful. I am not able to trigger this error
    > myself so I can't even do trial and error.
    >
    Winista, Sep 7, 2006
    #2
    1. Advertising

  3. No however the DLL is used to do these same operations thousands of
    time and has been around for years and there has been no mention of any
    problem like this on their mailing list. We have been using this
    EXACT same dll on our web site to do reprojections (classic ASP) for
    years hundreds of thousands of times a day.

    Winista wrote:
    > Did you develop unmanaged proj.dll? Do you source for that DLL?
    > That code seems to be causing some meory overwrite.
    >
    > "humbleaptience" <> wrote in message
    > news:...
    > >I have a web application that uses a DLL using DLLImport.
    > >
    > > Twice I have put the application live on the net and it has been used
    > > hundreds or thousands of time before it has been strangely brought
    > > down.
    > >
    > > System.AccessViolationException: Attempted to read or write protected
    > > memory. This is often an indication that other memory is corrupt. at
    > > ProjApi.Proj.pj_init_plus(String pjstr) at coordinate.LLtoUTM(Int32
    > > datumIn, Int32 datumOut, Double p_lat, Double p_lon, Double&
    > > UTMNorthing, Double& UTMEasting, Int32& UTMZone) at
    > > coordinate.LLtoUTMZone(Double lat, Double lon, Int32 datumIn, Int32
    > > datumOut, Int32& z, Double& n, Double& e) at
    > > getfactory.Page_Load(Object sender, EventArgs e) at
    > > System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
    > > Object t, EventArgs e) at
    > > System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
    > > EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at
    > > System.Web.UI.Control.LoadRecursive() at
    > > System.Web.UI.Page.ProcessRequestMain(Boolean
    > > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    > >
    > > Here is my code that calls the extern method
    > >
    > > public static int LLtoUTM(int datumIn, int datumOut, double p_lat,
    > > double p_lon,ref double UTMNorthing,ref double UTMEasting,ref int
    > > UTMZone)
    > > {
    > > int errno = 0;
    > > //This is the formula for calculating which Zone a point is in at a
    > > particular lat/long
    > > int ZoneNumber = Convert.ToInt32(Math.Floor((p_lon + 180) / 6)) + 1;
    > > double[] x = new double[1];
    > > double[] y = new double[1];
    > > double[] z = new double[1];
    > > y[0] = p_lat * ProjApi.Proj.DEG_TO_RAD;
    > > x[0] = p_lon * ProjApi.Proj.DEG_TO_RAD;
    > > z[0] = 0.0;
    > > IntPtr src0 = ProjApi.Proj.pj_init_plus("+proj=latlong
    > > +datum=NAD27");
    > > IntPtr src1 = ProjApi.Proj.pj_init_plus("+proj=latlong
    > > +datum=NAD83");
    > > IntPtr dst0 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
    > > + ZoneNumber + " +datum=NAD27");
    > > IntPtr dst1 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
    > > + ZoneNumber + " +datum=NAD83");
    > > //This nice little bit of code below is designed to execute
    > > pj_transfrom (the proj lib all around function)
    > > //with the correct parameters so that a datumshift to the correct
    > > datum is included.
    > > try
    > > {
    > > if (datumIn == 0)
    > > {
    > > if (datumOut == 0)
    > > {
    > > errno = ProjApi.Proj.pj_transform(src0, dst0,
    > > 1, 1, x, y, z);//NAD27-NAD83
    > > }
    > > else
    > > {
    > > errno = ProjApi.Proj.pj_transform(src0, dst1,
    > > 1, 1, x, y, z);//NAD27-NAD27
    > > }
    > > }
    > > else
    > > {
    > > if (datumOut == 0)
    > > {
    > > errno = ProjApi.Proj.pj_transform(src1, dst0,
    > > 1, 1, x, y, z);//NAD83-NAD27
    > > }
    > > else
    > > {
    > > errno = ProjApi.Proj.pj_transform(src1, dst1,
    > > 1, 1, x, y, z);//NAD83-NAD83
    > > }
    > > }
    > > }
    > > catch { }
    > >
    > > ProjApi.Proj.pj_free(dst1);
    > > ProjApi.Proj.pj_free(src1);
    > > ProjApi.Proj.pj_free(dst0);
    > > ProjApi.Proj.pj_free(src0);
    > > UTMNorthing = y[0];
    > > UTMEasting = x[0];
    > > UTMZone = ZoneNumber;
    > > return errno;
    > > }
    > >
    > >
    > > Here is the definition and DLL import.
    > > [DllImport("proj.dll", CharSet = CharSet.Ansi,
    > > CallingConvention = CallingConvention.Cdecl)]
    > > public static extern unsafe int pj_transform(IntPtr src, IntPtr
    > > dst,
    > > int point_count, int point_offset,
    > > [InAttribute, OutAttribute] double[] x,
    > > [InAttribute, OutAttribute] double[] y,
    > > [InAttribute, OutAttribute] double[] z);
    > >
    > > Any help at all would be useful. I am not able to trigger this error
    > > myself so I can't even do trial and error.
    > >
    humbleaptience, Sep 7, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. humbleaptience
    Replies:
    0
    Views:
    5,478
    humbleaptience
    Feb 22, 2006
  2. =?Utf-8?B?am9obm55Rw==?=

    Attempted to read or write protected memory

    =?Utf-8?B?am9obm55Rw==?=, Apr 19, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,681
    =?Utf-8?B?am9obm55Rw==?=
    Apr 19, 2006
  3. Dhruba Bandopadhyay
    Replies:
    0
    Views:
    5,216
    Dhruba Bandopadhyay
    May 12, 2006
  4. Sudhan
    Replies:
    1
    Views:
    631
  5. Replies:
    0
    Views:
    5,283
Loading...

Share This Page