From 26e5a066a947da12db10940bdef1b999b27e8566 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 11 Mar 2024 22:03:49 +0000 Subject: [PATCH 1/3] Fix #1453: Fix CsvProvider encoding provider registration --- src/FSharp.Data.DesignTime/Csv/CsvProvider.fs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs b/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs index 6561e381e..d5c08b1e6 100644 --- a/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs +++ b/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs @@ -18,6 +18,7 @@ open ProviderImplementation open ProviderImplementation.QuotationBuilder open FSharp.Data.Runtime.StructuralInference open System.Net +open System.Text // Added for CodePagesEncodingProvider // -------------------------------------------------------------------------------------- @@ -105,7 +106,15 @@ type public CsvProvider(cfg: TypeProviderConfig) as this = else value - CsvFile.Parse(value, separators, quote, hasHeaders, ignoreErrors, skipRows) + // Register CodePagesEncodingProvider before getting encoding + let provider = CodePagesEncodingProvider.Instance + Encoding.RegisterProvider provider + try + let encoding = TextRuntime.GetEncoding encodingStr + CsvFile.Parse(value, separators, quote, hasHeaders, ignoreErrors, skipRows, encoding) + finally + // Unregister CodePagesEncodingProvider after getting encoding + Encoding.UnregisterProvider provider let separators = sampleCsv.Separators From 788d584ac0715d53369c76742a6387c84f59248f Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 11 Mar 2024 22:09:12 +0000 Subject: [PATCH 2/3] Update CsvProvider.fs --- src/FSharp.Data.DesignTime/Csv/CsvProvider.fs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs b/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs index d5c08b1e6..6549231c7 100644 --- a/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs +++ b/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs @@ -109,12 +109,8 @@ type public CsvProvider(cfg: TypeProviderConfig) as this = // Register CodePagesEncodingProvider before getting encoding let provider = CodePagesEncodingProvider.Instance Encoding.RegisterProvider provider - try - let encoding = TextRuntime.GetEncoding encodingStr - CsvFile.Parse(value, separators, quote, hasHeaders, ignoreErrors, skipRows, encoding) - finally - // Unregister CodePagesEncodingProvider after getting encoding - Encoding.UnregisterProvider provider + let encoding = TextRuntime.GetEncoding encodingStr + CsvFile.Parse(value, separators, quote, hasHeaders, ignoreErrors, skipRows, encoding) let separators = sampleCsv.Separators From e4564d880f34aaacc1182bef5a5ec5baa2fe89f2 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 11 Mar 2024 22:09:38 +0000 Subject: [PATCH 3/3] Update CsvProvider.fs --- src/FSharp.Data.DesignTime/Csv/CsvProvider.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs b/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs index 6549231c7..02fbf7aa9 100644 --- a/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs +++ b/src/FSharp.Data.DesignTime/Csv/CsvProvider.fs @@ -18,7 +18,7 @@ open ProviderImplementation open ProviderImplementation.QuotationBuilder open FSharp.Data.Runtime.StructuralInference open System.Net -open System.Text // Added for CodePagesEncodingProvider +open System.Text // --------------------------------------------------------------------------------------