fsprojects / ExcelProvider

This library is for the .NET platform implementing a Excel type provider.
http://fsprojects.github.io/ExcelProvider/
The Unlicense
141 stars 51 forks source link

Is this meant to work with dotnet core? (System.Text.Encoding.CodePages dependency error) #68

Closed drk-mtr closed 3 years ago

drk-mtr commented 5 years ago

I'm new to F# so this may well be user error...

Description

I get the following error when trying to run a simple solution:

error FS3033: The type provider 'FSharp.Interop.Excel.ExcelProvider.ProviderImplementation+ExcelProvider' reported an error: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file.

I was going to log as an issue but I'm not sure whether the ExcelProvider is actually meant to work on .net core yet?

Known workarounds

Use full framework? Code works fine when running from .fsx, and intellisense (Ionide in vscode) is working correctly at design time.

Related information

quintusm commented 5 years ago

HI The provider is intended to work with dotnet core. Dot net framework (included with Windows) includes the different code pages. Working on dot net core you need to register it explicitly when using ExcelProvider.

Adding the following line to your application startup should solve the issue: System.Text.Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)

drk-mtr commented 5 years ago

Thanks for the help! Unfortunately I can't get that working, but I may have misunderstood where I need to register it. I've tried this:

open FSharp.Interop.Excel
open System.Text

type Xl = ExcelFile<"Book1.xlsx">

[<EntryPoint>]
let main argv =

    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)
    let xl = Xl().Data
    printfn "%s" (xl |> Seq.map (fun s -> s.test1.ToString()) |> String.concat "" )

    0

Also tried moving the Encoding... line outside of the main method and putting do in front of it but no joy.

quintusm commented 5 years ago

I would have expected that to work. What platform are you running on (Windows, Linux or Mac, and which version) ?

If you could upload a zip file or point to a repo or gist I could try to assist with troubleshooting.

quintusm commented 5 years ago

Also, please note that you need to have the correct package installed. You can install it via nuget with the dotnet command line as follows: dotnet add package System.Text.Encoding.CodePages or via paket as you mentioned in your initial post

tforkmann commented 5 years ago

Hey,

I just ran into the same issue.

I create a testproject with my latest state: https://github.com/tforkmann/ExcelProviderTest

Any help would be appreciated.

quintusm commented 5 years ago

HI @tforkmann I had a look at this, but could not resolve it in the time I had available. This is some dependency resolution error that is breaking the build. I will try to investigate further. This used to work before, so not sure what changed

quintusm commented 4 years ago

HI

My apologies for long delayed response. It seems that if you are targeting dotnet core or netstandard you need to explicitly add references to the following nuget packages:

I will see if there is some way to specify this via nuget so the dependencies are automatically included

quintusm commented 4 years ago

The above nuget packages worked for me in interactive window. However, running as a Console App I also needed to add the following nuget packages

At time of writing I targeted netcoreapp3.1. The package references in the project file where as follows: ``

<PackageReference Include="ExcelDataReader.DataSet" Version="3.6.0" />
<PackageReference Include="ExcelProvider" Version="1.0.1" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.0" />

``

quintusm commented 4 years ago

I do not understand why the above is necessary as these dependencies are specified in the nuget package and should be automagically resolved via the nuget restore infrastructure.

drchanix commented 4 years ago

https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding.registerprovider?view=netframework-4.8 Encoding.RegisterProvider(EncodingProvider) Applies to .NET Core 3.1 3.0 2.2 2.1 2.0 1.1 1.0 .NET Framework 4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 .NET Standard 2.1 2.0 1.6 1.4 1.3 UWP 10.0 Xamarin.Android 7.1 Xamarin.iOS 10.8 Xamarin.Mac 3.0

quintusm commented 3 years ago

This issue should be resolved with Version 2.0.0 release which is only targeting netstandard 2.0