MagicFileEncoding 2.0.0

.NET 6.0
dotnet add package MagicFileEncoding --version 2.0.0
NuGet\Install-Package MagicFileEncoding -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MagicFileEncoding" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MagicFileEncoding --version 2.0.0
#r "nuget: MagicFileEncoding, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MagicFileEncoding as a Cake Addin
#addin nuget:?package=MagicFileEncoding&version=2.0.0

// Install MagicFileEncoding as a Cake Tool
#tool nuget:?package=MagicFileEncoding&version=2.0.0

Magic File Encoding

NuGet Downloads Actions Status

The Magic File Encoding lib helps to load and transform simple and closed scope char set text files (like EDIFACT).

Be aware of possible transformation issues if the target encoding is simpler than the source encoding.

It is strongly recommended to write unit tests for your use case to ensure the load and transformation works as expected.

Nuget Package

MagicFileEncoding at

Versioning & Breaking Changes


  • Major: Breaking changes
  • Minor: New features, but backwards compatible
  • Patch: Backwards compatible bug fixes only
  • -Suffix (optional): a hyphen followed by a string denoting a pre-release version



Read a text file
var text = FileEncoding.ReadAllText(filePath);
// or 
var text = FileEncoding.ReadAllText(filePath, Encoding.Unicode);
Write a text file
FileEncoding.WriteAllText(tmpFile.Path, text, Encoding.UTF8);
Just detect suitable encoding
var encoding = FileEncoding.GetAcceptableEncoding(filename);

Fallback Encoding

The fallback encoding is ISO-8859-1 (Latin-1) by default but can be changed via optional method argument.

(Because this lib was designed for the german culture space)


This work is heavily based on the following stack overflow and web articles:<br /> determine-a-strings-encoding-in-c-sharp <br /> check-for-invalid-utf8 <br /> how-to-detect-utf-8-in-plain-c <br /> strip-byte-order-mark-from-string-in-c-sharp <br /> what-is-the-most-common-encoding-of-each-language <br /> utf-bom4

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 49 5/25/2023
1.1.1 1,193 2/13/2021
1.1.0 253 2/13/2021
1.0.0 359 9/28/2020
1.0.0-preview.3 213 9/28/2020
1.0.0-preview.2 253 9/27/2020
1.0.0-preview 317 9/27/2020