CsvHelper is the default answer for CSV in .NET, and it earns that by hiding the tedious part: you hand it a DTO and it figures out the columns. The way it figures them out is the part that collides with an obfuscator. When CsvHelper needs a column header for a member — to write the header row, or to find that member's column when reading — its default source for that header is the member's own name. public string FirstName becomes a column headed FirstName. That derivation reads the member's metadata name at runtime, and an obfuscator's whole job is to replace that name with a. So the moment you protect the assembly, FirstName becomes a, your exported files grow a column headed a, and importing a file that still says FirstName throws.
The failure is asymmetric in a way worth stating up front, because it decides how you find out. Writing is silent: WriteRecords happily emits a header row of a,b,c and every downstream consumer keyed on FirstName quietly breaks. Reading is loud: GetRecords<T>() validates that each mapped member's expected header exists in the file, and after a rename the member expects a while the file says FirstName, so CsvHelper throws a HeaderValidationException on the first row. The good news is that the whole dependency is on one string per member, and CsvHelper gives you a first-class way to set that string explicitly — which turns the problem off entirely, with no Nebula.NET keep-list required.
How CsvHelper turns a member into a header
Two paths produce a member-to-header binding, and both default to the member name.
The first is AutoMap, used whenever you call GetRecords<T>() or WriteRecords without registering a map. CsvHelper reflects over T, enumerates its public members, and for each one creates a MemberMap whose header name is seeded from MemberInfo.Name. There is no attribute, no configuration — the property's CLR name is the column name.
The second is an explicit ClassMap, where you write Map(m => m.FirstName). That m => m.FirstName is an Expression<Func<T, object>>. CsvHelper walks the expression tree down to its MemberExpression and pulls out the MemberInfo it references. This is the subtle part under obfuscation: the expression is compiled code, and after a rename it still carries a direct reference to the renamed member — so Map(m => m.FirstName) binds to the right member even when that member is now called a. The binding survives. What does not survive is the header name, because a bare Map(m => m.FirstName) with no .Name() falls back to exactly the same MemberInfo.Name derivation as AutoMap. The expression pins the member; it does nothing for the header string.
Why the values are fine but the header moves
It helps to separate the two things CsvHelper handles, because only one of them is fragile. The cell values — the actual data in each row — are read and written positionally and by the materializer CsvHelper builds for the type; they never depend on a header string. The header row is the only place a member's name becomes externally visible text. So renaming never corrupts your data; it corrupts the one line of the file that names your columns.
That line, though, is the contract with everyone else. A finance system that ingests your export looks for a FirstName column. A partner who sends you a CSV puts FirstName in row one. Both sides agreed on that spelling, and the obfuscator just changed your side of it to a without telling the other. The whole job, then, is to keep the header spelling fixed while letting the member name underneath it move freely.
Here is the DTO and the two ways to map it, written the way shipped code should look:
public sealed class Customer { public int Id { get; set; } public string FirstName { get; set; } = ""; public string LastName { get; set; } = ""; public string Email { get; set; } = ""; } // Fragile: AutoMap derives every header from the member name. using var reader = new CsvReader(stream, CultureInfo.InvariantCulture); var rows = reader.GetRecords<Customer>().ToList(); // expects headers FirstName, LastName, ... After obfuscation, GetRecords<Customer>() builds auto-maps whose members are now named a, b, c. CsvHelper validates the header row, finds no column headed a, and throws:
CsvHelper.HeaderValidationException: Header with name 'a'[0] was not found. Header with name 'b'[0] was not found. The exception is almost helpful — it tells you the member it expected a header for is now called a. That is the rename leaking straight into a runtime error.
The fix: an explicit ClassMap pins the header, not the name
Register a ClassMap and give every member an explicit .Name(). Now the header comes from a string literal in your map, not from the member's metadata, so the member is free to rename and the header does not move:
public sealed class CustomerMap : ClassMap<Customer> { public CustomerMap() { Map(m => m.Id).Name("Id"); Map(m => m.FirstName).Name("First Name"); Map(m => m.LastName).Name("Last Name"); Map(m => m.Email).Name("Email"); } } // Register once, then read or write as normal. using var csv = new CsvReader(stream, CultureInfo.InvariantCulture); csv.Context.RegisterClassMap<CustomerMap>(); var rows = csv.GetRecords<Customer>().ToList(); Three things are now rename-proof at once, and it is worth being precise about why:
- The member binding comes from the expression
m => m.FirstName, which is compiled IL holding a direct member reference. Nebula renamesFirstNametoaand rewrites that reference in the expression at the same time, so the map still points at the right member. Renaming is internally consistent; the expression and the field move together. - The header name comes from the
"First Name"literal. Nebula may encrypt that literal so it is not sitting in plaintext in your assembly, but string encryption is transparent at runtime — it decrypts to the exact bytes you wrote. The header is never an identifier in your metadata, so the rename pass never touches it. - The map type
CustomerMapis referenced byRegisterClassMap<CustomerMap>()through itsType, not by a name string, so Nebula renamesCustomerMaptoaand the generic registration still resolves it.
The consequence is the clean one: with a fully explicit ClassMap, your DTO needs no keep-list at all. Every public member of Customer can be renamed, because nothing reads their names — CsvHelper reads your literals. That is the opposite of a reflection-by-name library where you must pin the members; here you simply move the names you depend on out of metadata and into literals the obfuscator leaves alone.
When you still need a keep-list
Two situations keep the member name load-bearing, and for those the explicit map is not in play, so you pin instead.
The first is AutoMap with no map at all — the quick GetRecords<T>() path with no RegisterClassMap. If you want to keep that convenience and not write maps, you must preserve the public member names CsvHelper derives headers from. In nebula.config.json, pin the DTOs' public surface and rename everything else:
{ "input": "bin/Release/net8.0/Acme.Import.dll", "rename": { "enabled": true, "keep": [ { "namespace": "Acme.Import.Records", "kind": "type", "members": "public", "reason": "CsvHelper AutoMap derives CSV headers from these public member names" } ] }, "strings": { "encrypt": true }, "controlFlow": { "enabled": true } } The "members": "public" scope is deliberate: it preserves the public property names CsvHelper reads while still letting Nebula rename private backing fields, which the mapper never touches. The second situation is a ClassMap with Map(m => m.FirstName) but no .Name() — a half-done map that pins the binding but still derives the header from the name. The fix there is not a keep-list; it is to finish the map by adding .Name("...") to every member. A keep-list on a half-done map works, but it leaves identifiers readable to protect a header you could have moved into a literal in one line.
Verify with Glass before you ship
Confirm the rename did what you intended with Glass, the free .NET decompiler. Open the protected assembly and check two shapes. First, the CustomerMap constructor: the Map(...) calls should still carry your "First Name", "Last Name" literals (encrypted literals show as a decrypt call, which is expected — the point is that no header was turned into a). Second, the Customer type: with an explicit map its members should appear renamed to a, b, c, which proves the DTO was actually protected and not needlessly kept. If you are on the AutoMap path instead, invert the second check — the Customer members should still read FirstName, LastName, which proves the keep-list held.
Then run one integration test that writes a record and reads it back, asserting the header row text is exactly what external systems expect. That single round-trip catches the silent write-side failure that no exception would ever surface.
The shape of the rule
CsvHelper's dependency on your code is one string per member: the column header. By default it reads that string from the member's name, so an obfuscator that renames the member rewrites your headers — silently on write, loudly on read. Move the header into an explicit .Name("...") literal and the dependency moves with it: the member is free to rename, the header is a literal the obfuscator leaves intact, and the DTO needs no keep-list. Reach for the keep-list only when you deliberately keep the AutoMap convenience, pin just the public members CsvHelper derives headers from, and verify the result in Glass before the file ever reaches someone else's parser.
