Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 381961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:08:10+00:00 2026-05-12T15:08:10+00:00

We have inherited a legacy system for reading to and from meter guns. This

  • 0

We have inherited a legacy system for reading to and from meter guns. This system was originally build on XP with .Net 1.1 (VS2003?). Having recompiled it on VS2008 with .net 3.5 we get an access violation when calling the dll (dll not touched). The original program (using basically the same code) is running fine on our production machine.

Crash:

[System.AccessViolationException]
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Code:

[DllImport("tinydb.dll",CallingConvention=CallingConvention.Cdecl)]
static extern Int16 db_fillnew(Int16 recno,IntPtr buffer,Int16 dbn);
     :
     :
    IntPtr buffer = Marshal.AllocHGlobal(1024); 
     :
     :
foreach (Round round in roundList)
{
    RoundRec roundRec=new RoundRec();
    roundRec.Book=Int16.Parse(round.Reference);
    roundRec.NLegend=round.Name;
    Marshal.StructureToPtr(roundRec,buffer,true);
    status = db_fillnew(ROUND_REC,buffer,0); // <=CRASHES HERE

It always crashes on the second time around the loop.

Here is the record structure:

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct RoundRec
{
    public Int16 Book;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
    public string NLegend; public string LastReadRefNo;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
    public string LastNoAccessRefNo;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:08:11+00:00Added an answer on May 12, 2026 at 3:08 pm

    Try allocating and freeing the memory for each record:

    foreach (Round round in roundList)
    {
      RoundRec roundRec = new RoundRec();
      roundRec.Book=Int16.Parse(round.Reference);
      roundRec.NLegend = round.Name;
    
      IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(roundRec));
    
      Marshal.StructureToPtr(roundRec, buffer, true);
      status = db_fillnew(ROUND_REC, buffer, 0);
    
      Marshal.FreeHGlobal(buffer);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inherited work from a previous employee. The issue I'm having is a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I have inherited a set of legacy webservices (VB.Net, IIS hosted ASMX) in which
I have a legacy application that I inherited that passes a lot of XML
I have inherited a few programs from a previous developer who was a little
I have inherited couple of .Net (C#) application which does not have any tracing
We have inherited a vb.net 2003 web project, it seems to reference another web
I have inherited some legacy HTML in which it has the following elements in
I have inherited some legacy code which generates a ton of inline styles. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.