Visual FoxPro to C#.NET migration
Working example built by Estrada Consulting, Inc. for RFQ BD-27-1003-EOAS-EOAS-135643, Executive Office for Administration and Finance

Translation traps

Ten Visual FoxPro constructs that a general purpose code assistant translates plausibly and wrongly. Each one carries the VFP source, the translation a naive pass produces, why it is wrong, the translation ECI accepts, and a check that runs on this page over the fixture rows. These are the defects that survive a code review and surface in production as a number that is quietly off.

T01. Empty date is not NULL check separates them

Visual FoxPro

IF EMPTY(lcRec.dClosed)
   lnDays = 0
ELSE
   lnDays = DATE() - lcRec.dClosed
ENDIF

What a naive pass produces

if (rec.DClosed == null)
    days = 0;
else
    days = (DateTime.Today - rec.DClosed.Value).Days;

What ECI accepts

// Empty VFP date arrives as DateTime.MinValue or 1899-12-30 after the DBF import,
// so the port tests for both, and the import maps them to NULL once, in one place.
static bool IsVfpEmpty(DateTime? d) =>
    d is null || d == DateTime.MinValue || d.Value.Date == new DateTime(1899, 12, 30);

Why it matters. A VFP date field is never null. An unset date is the empty date, which DBF stores as blanks and a straight import lands in SQL Server as 1899-12-30 or as the minimum date, not as NULL. The naive test for null is false for every empty date, so every unclosed record gets an age measured from 1899 and the aging report reads in the tens of thousands of days.

Check T01, run on this page over the fixture rows: Days open for the two records with no close date
RunResultMatches Visual FoxPro
Visual FoxPro0, 0authority
Naive translation46356, 46356no
ECI translation0, 0yes

T02. Comparison with = is a prefix match check separates them

Visual FoxPro

SET EXACT OFF
IF lcOrg = 'DOR'
   * matches DOR, DORA, DOR-APPEALS
ENDIF

What a naive pass produces

if (org == "DOR")

What ECI accepts

// The module relied on SET EXACT OFF, so the port keeps the prefix semantics
// explicitly rather than inheriting them from a global setting nobody can see.
if (org.StartsWith("DOR", StringComparison.OrdinalIgnoreCase))

Why it matters. With SET EXACT OFF, which is the VFP default, the = operator compares only to the length of the right hand side. So 'DORA' = 'DOR' is true in FoxPro and false in C#. A module that selected three organizations now selects one, and the totals drop without any error.

Check T02, run on this page over the fixture rows: Organization codes matched by the module's filter
RunResultMatches Visual FoxPro
Visual FoxProDOR, DOR, DOR-APPEALS, DORAauthority
Naive translationDOR, DORno
ECI translationDOR, DOR, DOR-APPEALS, DORAyes

T03. Trailing blanks in a character field check separates them

Visual FoxPro

lcKey = ALLTRIM(cAppealNo) + '-' + ALLTRIM(cOrgCode)

What a naive pass produces

key = rec.CAppealNo + "-" + rec.COrgCode;

What ECI accepts

// Every character column from the DBF import is right padded. Trim at the edge,
// once, where the row is read, rather than at each use.
key = $"{rec.CAppealNo.TrimEnd()}-{rec.COrgCode.TrimEnd()}";

Why it matters. A DBF character field is fixed width and padded with blanks. Dropping ALLTRIM leaves 'A-2026-0001 -DOR ', so the key never matches the key built anywhere else, and the join silently produces nothing.

Check T03, run on this page over the fixture rows: Join keys, as built from fixed width DBF columns
RunResultMatches Visual FoxPro
Visual FoxProA-2026-0001-DOR, A-2026-0002-DORA, A-2026-0003-DOR-APPEALS, A-2026-0004-ANF, A-2026-0005-DORauthority
Naive translationA-2026-0001 -DOR , A-2026-0002 -DORA , A-2026-0003 -DOR-APPEALS , A-2026-0004 -ANF , A-2026-0005 -DOR no
ECI translationA-2026-0001-DOR, A-2026-0002-DORA, A-2026-0003-DOR-APPEALS, A-2026-0004-ANF, A-2026-0005-DORyes

T04. SCAN respects the current filter and deleted rows check separates them

Visual FoxPro

SET DELETED ON
SET FILTER TO nAmount > 0
SCAN
   lnTotal = lnTotal + nAmount
ENDSCAN

What a naive pass produces

foreach (var r in rows)
    total += r.NAmount;

What ECI accepts

// The filter and SET DELETED were set in the calling program. They are part of
// the module's behavior, so they become part of the query and are stated here.
total = rows.Where(r => !r.Deleted && r.NAmount > 0).Sum(r => r.NAmount);

Why it matters. SCAN walks the rows the current filter and SET DELETED leave visible. The filter and the deleted flag are usually set in a different procedure, so the loop body looks unconditional in the source being translated. The port totals rows the original never saw, including rows marked deleted but never packed.

Check T04, run on this page over the fixture rows: Sum of nAmount under SET DELETED ON and SET FILTER TO nAmount > 0
RunResultMatches Visual FoxPro
Visual FoxProDecimal('1583333.32')authority
Naive translationDecimal('1628333.57')no
ECI translationDecimal('1583333.32')yes

T05. Macro substitution builds the code at run time check separates them

Visual FoxPro

lcField = 'nAssessed'
lnValue = &lcField
lcWhere = "cStatus = 'O'"
SELECT * FROM appeals WHERE &lcWhere INTO CURSOR cTmp

What a naive pass produces

// assistant emits a literal, having guessed the one value it saw
value = rec.NAssessed;

What ECI accepts

// Macro substitution becomes an explicit, closed set. Anything outside it throws,
// so an unexpected field name is a loud failure and not a silent default.
static readonly Dictionary<string, Func<AppealRow, decimal>> FieldMap = new()
{
    ["nAssessed"] = r => r.NAssessed,
    ["nAbated"]   = r => r.NAbated,
    ["nPenalty"]  = r => r.NPenalty,
};
value = FieldMap.TryGetValue(fieldName, out var f)
    ? f(rec)
    : throw new InvalidOperationException($"Unmapped field {fieldName}");

Why it matters. The ampersand expands a string into source at run time. Whatever the variable held on the day the sample ran is not the whole behavior, and a translation that freezes one value quietly drops every other branch. This is the single construct that most often turns a correct looking port into a wrong one.

Check T05, run on this page over the fixture rows: Value returned for each of the three field names the caller passes
RunResultMatches Visual FoxPro
Visual FoxProDecimal('100.00'), Decimal('40.00'), Decimal('7.50')authority
Naive translationDecimal('100.00'), Decimal('100.00'), Decimal('100.00')no
ECI translationDecimal('100.00'), Decimal('40.00'), Decimal('7.50')yes

T06. Numeric fields are decimal, not float check separates them

Visual FoxPro

nAmount = 1234567.89

What a naive pass produces

public double NAmount { get; set; }

What ECI accepts

// Fixed point in, fixed point through. decimal end to end, with the DBF's own
// width and decimal count carried into the SQL Server column definition.
public decimal NAmount { get; set; }   // numeric(12,2)

Why it matters. A DBF numeric column is fixed point. Binding it to double introduces representation error that shows up after a few thousand additions, so a reconciliation that balanced in FoxPro is out by cents in the port. On an abatement total that is a finding, not a rounding note.

Check T06, run on this page over the fixture rows: Ten thousand additions of one cent
RunResultMatches Visual FoxPro
Visual FoxProDecimal('100.00')authority
Naive translationDecimal('100.00000000001425')no
ECI translationDecimal('100.00')yes

T07. Logical fields are .T., .F. or blank check separates them

Visual FoxPro

IF lRemanded
   * blank reads as .F.
ENDIF

What a naive pass produces

public bool LRemanded { get; set; }

What ECI accepts

// Blank is kept as a third state until the business decides what it means,
// which is a question for A&F and not for the migration.
public bool? LRemanded { get; set; }   // bit NULL

Why it matters. A DBF logical column holds T, F or a space. A never set flag is a space, which VFP reads as false but which a non nullable bool cannot represent, so the import either fails or defaults. Both outcomes lose the distinction between answered no and never asked, and that distinction matters in an appeals record.

Check T07, run on this page over the fixture rows: lRemanded read from each row, where a blank is neither true nor false
RunResultMatches Visual FoxPro
Visual FoxProTrue, None, False, True, Falseauthority
Naive translationTrue, False, False, True, Falseno
ECI translationTrue, None, False, True, Falseyes

T08. Work areas and unqualified field names check separates them

Visual FoxPro

SELECT appeals
SET RELATION TO cOrgCode INTO orgs
SCAN
   ? cOrgName
ENDSCAN

What a naive pass produces

foreach (var a in appeals)
    Console.WriteLine(a.COrgName);

What ECI accepts

// The relation is a join, and the port says which table each column comes from.
var q = from a in appeals
        join o in orgs on a.COrgCode.TrimEnd() equals o.COrgCode.TrimEnd()
        select new { a.CAppealNo, o.COrgName };

Why it matters. cOrgName is not a column of appeals. It resolves through the relation into the orgs work area, and VFP finds it by searching the open work areas in order. Field names in the source do not say which table they come from, so a translation that assumes one table compiles and then fails, or worse, binds to a same named column on the wrong table.

Check T08, run on this page over the fixture rows: cOrgName for each open appeal, resolved through the relation
RunResultMatches Visual FoxPro
Visual FoxProDepartment of Revenue, Department of Revenue, Appeals, Appellate Tax Board liaison, Administration and Financeauthority
Naive translation, , , no
ECI translationDepartment of Revenue, Department of Revenue, Appeals, Appellate Tax Board liaison, Administration and Financeyes

T09. REPLACE writes to the whole filtered set check separates them

Visual FoxPro

REPLACE ALL cStatus WITH 'C' FOR dClosed <= DATE()

What a naive pass produces

foreach (var r in rows)
    if (r.DClosed <= DateTime.Today) r.CStatus = "C";

What ECI accepts

// One statement, one transaction, the same row set the original saw.
await using var tx = await conn.BeginTransactionAsync();
await conn.ExecuteAsync(
    "UPDATE appeals SET cStatus = 'C' WHERE dClosed <= @today AND deleted = 0 AND nAmount > 0",
    new { today = DateTime.Today }, tx);
await tx.CommitAsync();

Why it matters. REPLACE ALL ... FOR runs against the rows the current filter leaves visible, in one pass, with no transaction. The port's loop runs against everything it was handed, and it commits row by row. A failure halfway through leaves the FoxPro run unchanged and the port's run half applied.

Check T09, run on this page over the fixture rows: Appeal numbers the update sets to closed
RunResultMatches Visual FoxPro
Visual FoxProA-2026-0001authority
Naive translationA-2026-0001, A-2026-0002, A-2026-0003, A-2026-0004, A-2026-0005no
ECI translationA-2026-0001yes

T10. Office automation is behavior, not plumbing check separates them

Visual FoxPro

oExcel = CREATEOBJECT('Excel.Application')
oExcel.Workbooks.Open(lcPath)
oSheet.Range('B2').Value = lnTotal

What a naive pass produces

// assistant proposes the same COM interop under .NET

What ECI accepts

// The output is a workbook, not an Excel session. A file writer produces the same
// workbook from a service account with no Office installed, which is what lets the
// same component run both scheduled and on demand, as the RFQ requires.
using var wb = new XLWorkbook();
var ws = wb.AddWorksheet("Abatements");
ws.Cell("B2").Value = total;
wb.SaveAs(outputPath);

Why it matters. The RFQ names interaction with Microsoft Office products as a reason the target may need to be a Windows application. Carrying COM interop forward keeps the dependency on an installed Excel, on a desktop session, and on a licence, which is exactly what breaks a scheduled run on a server at two in the morning.

Check T10, run on this page over the fixture rows: Whether the scheduled run succeeds on a server with no Office installed
RunResultMatches Visual FoxPro
Visual FoxProruns unattended under a service accountauthority
Naive translationneeds an interactive desktop session with Excel installedno
ECI translationruns unattended under a service accountyes