I am using the R Type Provider like so in the REPL
#r "../packages/FSharp.Data.2.2.0/lib/net40/FSharp.Data.dll"
open FSharp.Data
[<Literal>]
let uri = "https://reddoggabtest-secondary.table.core.windows.net/TestTelemetryData0?tn=TestTelemetryData0&sv=2014-02-14&si=GabLab&sig=GGc%2BHEa9wJYDoOGNE3BhaAeduVOA4MH8Pgss5kWEIW4%3D"
type CarTelemetry = XmlProvider<uri>
let carTelemetry = CarTelemetry.Load(uri)
#r "C:/Program Files (x86)/Reference Assemblies/Microsoft/Framework/.NETFramework/v4.5.1/System.Xml.Linq.dll"
open System.Xml.Linq
carTelemetry.Entries |> Seq.iter(fun e -> printfn "%A" e.Title)
#I "../packages/RProvider.1.1.8/lib"
#r "../packages/R.NET.1.5.5/lib/net40/RDotNet.dll"
#r "../packages/R.NET.1.5.5/lib/net40/RDotNet.NativeLibrary.dll"
#r "../packages/R.NET.Community.FSharp.0.1.9/lib/net40/RDotNet.FSharp.dll"
#r "../packages/RProvider.1.1.8/lib/net40/RProvider.dll"
#r "../packages/RProvider.1.1.8/lib/net40/RProvider.Runtime.dll"
open System
open System.Net
open RDotNet
open RProvider
open RProvider.graphics
open RProvider.stats
carTelemetry.Entries |> Seq.map(fun e -> e.Content.Properties.Acceleration.Value)
|> R.log
|> R.diff
When I execute it, I am getting this exception
System.MissingMethodException: Method not found: 'RDotNet.REngine RDotNet.REngine.GetInstance(System.String, Boolean, RDotNet.StartupParameter, RDotNet.Devices.ICharacterDevice)'.
at RProvider.Internal.RInit.engine#114.Invoke()
at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Lazy`1.get_Value()
at RProvider.RInteropInternal.toR(Object value) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 287
at RProvider.RInterop.passArg#447(List`1 tempSymbols, Object arg) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 461
at RProvider.RInterop.argList#468-1.GenerateNext(IEnumerable`1& next) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 475
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System-Collections-IEnumerator-MoveNext()
at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
at RProvider.RInterop.callFunc(String packageName, String funcName, IEnumerable`1 argsByName, Object[] varArgs) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 466
at <StartupCode$FSI_0012>.$FSI_0012.main#()
Stopped due to error
Any ideas? Thanks.
This looks like some version mismatch - what version(s) of R.NET do you have installed in the packages folder?
The correct ones (as required by the latest R provider NuGet package) are:
R.NET.Community (= 1.5.16)
R.NET.Community.FSharp (= 0.1.9)
Note that there is (confusingly) also older R.NET package (without the "Community" bit) and having that in packages can probably confuse the R provider.
BTW: You can also try using the FsLab templates instead, which makes the process of installing & loading everything a lot simpler - reduces all to just a single #load :-)
Related
New F# Program
Add nuget package FSharp.Data
Attempt to run this code
open FSharp.Data
let doc = #"<!DOCTYPE html><html><body><p>FSharp!</p></body></html>" |> Encoding.UTF8.GetBytes |> MemoryStream |> HtmlDocument.Load
CssSelectorExtensions.CssSelect (doc, "p") |> LINQPad.Extensions.Dump
The execution of the CssSelect function throws the error
Method not found: 'Microsoft.FSharp.Collections.FSharpList`1<FSharp.Data.HtmlNode> CssSelectorExtensions.CssSelect(FSharp.Data.HtmlDocument, System.String)'.
Same error in both LinqPad 5 and 6.
Code runs fine in VS 2019 (without the Dump function obviously)
Can anyone repo ? Why the error in LinqPad ?
Adding FSharp.Core from nuget to the query got rid of the error
I have a F# fake script which works with Nuge.Core to extract package files. If I try to do this with c# console app everything works properly. However if I execute exactly the same script in a f# fake script it is not working. There are so many dependencies here and I have no idea where to look for a help: docker.dotnet, fake, f#, nuget.core
To reproduce this you need to download Docker.DotNet.2.124.3.nupkg
For the c# sample you need console application and to install nuget.core nuget package. This is working!
class Program
{
static void Main()
{
var zip = new NuGet.ZipPackage(#"Docker.DotNet.2.124.3.nupkg");
foreach (var file in zip.GetFiles())
{
System.Console.WriteLine(file.Path);
}
}
}
For the f# sample you need these two files side by side:
https://gist.github.com/mynkow/e6f0e550fcacc268dd1e9b743e17d344
ERROR:
==============================================================================
FsiEvaluationException:
Error: System.InvalidOperationException: 'NETStandard.Library' already has a dependency defined for 'Microsoft.NETCore.Platforms'.
at NuGet.Manifest.ValidateDependencySets(IPackageMetadata metadata)
at NuGet.Manifest.Validate(Manifest manifest)
at NuGet.Manifest.ReadFrom(Stream stream, IPropertyProvider propertyProvider, Boolean validateSchema)
at NuGet.LocalPackage.ReadManifest(Stream manifestStream)
at NuGet.ZipPackage.EnsureManifest(Func`1 manifestStreamFactory)
at NuGet.ZipPackage..ctor(String filePath, Boolean enableCaching)
at <StartupCode$FSI_0005>.$FSI_0005_Test$fsx.main#() in C:\Users\mynkow\Desktop\Reproduce\test.fsx:line 12
Stopped due to error
Output: [Loading C:\Users\mynkow\Desktop\Reproduce\test.fsx]
==============================================================================
Input: C:\Users\mynkow\Desktop\Reproduce\test.fsx
\Arguments:
C:\fsi.exe
Exception: Yaaf.FSharp.Scripting.FsiEvaluationException: Error while compiling or executing fsharp snippet. ---> System.Exception: Operation failed. The error text has been print the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing
at Microsoft.FSharp.Compiler.Interactive.Shell.FsiEvaluationSession.commitResult[a,b](FSharpChoice`2 res)
at Microsoft.FSharp.Compiler.Interactive.Shell.FsiEvaluationSession.EvalScript(String filePath)
at Yaaf.FSharp.Scripting.Helper.evalScript#1303.Invoke(String arg00) in C:\code\FAKE\paket-files\matthid\Yaaf.FSharp.Scripting\src\source\Yaaf.FSharp.Scripting\YaafFSharpScripting.fs:line 1303
at Yaaf.FSharp.Scripting.Helper.save_#1276-2.Invoke(Unit unitVar0) in C:\code\FAKE\paket-files\matthid\Yaaf.FSharp.Scripting\src\source\Yaaf.FSharp.Scripting\YaafFSharpScripting.fs:line 1277
at Yaaf.FSharp.Scripting.Helper.consoleCapture[a](TextWriter out, TextWriter err, FSharpFunc`2 f) in C:\code\FAKE\paket-files\matthid\Yaaf.FSharp.Scripting\src\source\Yaaf.FSharp.Scripting\YaafFSharpScripting.fs:line 1221
at Yaaf.FSharp.Scripting.Helper.redirectOut#1247[a](Boolean preventStdOut, OutStreamHelper out, OutStreamHelper err, FSharpFunc`2 f) in C:\code\FAKE\paket-files\matthid\Yaaf.FSharp.Scripting\src\source\Yaaf.FSharp.Scripting\YaafFSharpScripting.fs:line 1254
at Yaaf.FSharp.Scripting.Helper.save_#1275-1.Invoke(String text) in C:\code\FAKE\paket-files\matthid\Yaaf.FSharp.Scripting\src\source\Yaaf.FSharp.Scripting\YaafFSharpScripting.fs:line 1276
--- End of inner exception stack trace ---
at Yaaf.FSharp.Scripting.Helper.save_#1275-1.Invoke(String text) in C:\code\FAKE\paket-files\matthid\Yaaf.FSharp.Scripting\src\source\Yaaf.FSharp.Scripting\YaafFSharpScripting.fs:line 1284
at Yaaf.FSharp.Scripting.Helper.session#1306.Yaaf-FSharp-Scripting-IFsiSession-EvalScriptWithOutput(String ) in C:\code\FAKE\paket-files\matthid\Yaaf.FSharp.Scripting\src\source\Yaaf.FSharp.Scripting\YaafFSharpScripting.fs:line 1308
at Fake.FSIHelper.runScriptUncached(Boolean useCache, String scriptPath, IEnumerable`1 fsiOptions, Boolean printDetails, CacheInfo cacheInfo, TextWriter out, TextWriter err) in C:\code\FAKE\src\app\FakeLib\FSIHelper.fs:line 471
System.InvalidOperationException: 'NETStandard.Library' already has a dependency defined for 'Microsoft.NETCore.Platforms'.
at NuGet.Manifest.ValidateDependencySets(IPackageMetadata metadata)
at NuGet.Manifest.Validate(Manifest manifest)
at NuGet.Manifest.ReadFrom(Stream stream, IPropertyProvider propertyProvider, Boolean validateSchema)
at NuGet.LocalPackage.ReadManifest(Stream manifestStream)
at NuGet.ZipPackage.EnsureManifest(Func`1 manifestStreamFactory)
at NuGet.ZipPackage..ctor(String filePath, Boolean enableCaching)
at <StartupCode$FSI_0005>.$FSI_0005_Test$fsx.main#() in C:\Users\mynkow\Desktop\Reproduce\test.fsx:line 12
Stopped due to error
I have tried with the 5 latest versions of all possible dependencies and the results are exactly the same => c# is working, f# is not. Do you have any clue or just anything which you can advise me to try to fix this?
DIRTY SOLUTION:
This is how the Docker.DotNet.2.124.3.nupkg looks like inside
If I remove for example the netstandard1.6 everything works. This means that the problem is in nuget.core, right? But why it is working in c# console app? No idea!
UPDATE: I am able to execute properly the code from F# console application
I've downloaded the packages with paket, and changed the script this way:
#r #"./packages/FAKE/tools/FakeLib.dll"
#r #"./packages/NuGet.Core/lib/net40-Client/NuGet.Core.dll"
open System
open System.Collections.Generic
open System.IO
open Fake
Target "Test" (fun _ ->
printfn "=============================================================================="
global.NuGet.ZipPackage(#"Docker.DotNet.2.124.3.nupkg").GetFiles() |> Seq.iter(fun x -> printfn "%s" x.Path )
)
RunParameterTargetOrDefault "target" "test"
It gives this
Microsoft (R) F# Interactive version 14.0.23413.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
>
--> Referenced 'C:\tmp\visualfsharp.issue.nuget\./packages/FAKE/tools/FakeLib.dll'
--> Referenced 'C:\tmp\visualfsharp.issue.nuget\./packages/NuGet.Core/lib/net40-Client/NuGet.Core.dll'
Building project with version: LocalBuild
Shortened DependencyGraph for Target Test:
<== Test
The resulting target order is:
- Test
Starting Target: Test
==============================================================================
Running build failed.
Error:
System.InvalidOperationException: The schema version of 'Docker.DotNet' is incompatible with version 1.6.30117.9648 of NuGet. Please upgrade NuGet to the latest version from http://go.microsoft.com/fwlink/?LinkId=213942.
at NuGet.Manifest.CheckSchemaVersion(XDocument document)
at NuGet.Manifest.ValidateManifestSchema(XDocument document, String schemaNamespace)
at NuGet.Manifest.ReadFrom(Stream stream, IPropertyProvider propertyProvider)
at NuGet.ZipPackage.EnsureManifest()
at FSI_0002.clo#9.Invoke(Unit _arg1) in C:\tmp\visualfsharp.issue.nuget\test.fsx:line 11
at Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) in C:\code\FAKE\src\app\FakeLib\TargetHelper.fs:line 493
---------------------------------------------------------------------
Build Time Report
No target was successfully completed
---------------------------------------------------------------------
---------------------------------------------------------------------
val it : unit = ()
>
The version of NuGet.Core is 2.12, and I'm seeing it is referencing Microsoft.Web.Xdt which is not loaded.
Maybe you can achieve what you want by simply using paket and adding Docker.DotNet as a dependency, it will extract it for you.
If you have reproducible error that you described, please make a zip and post an issue to visualfsharp repository.
I'm trying to use FAKE to build my F# project.
The build.fsx looks like below and works fine.
#r "packages/FAKE/tools/FakeLib.dll"
open Fake
Target "Default" (fun _ ->
trace "Hello World from FAKE"
)
RunTargetOrDefault "Default"
Then I want to use fsc from FAKE. Following the official tutorial, I added one line open Fake.FscHelper and get below error message:
#r "packages/FAKE/tools/FakeLib.dll"
open Fake
open Fake.FscHelper
// this value is not a function and can not be applied
// union case FscParam.Target: TargetType -> FscParam
Target "Default" (fun _ ->
~~~~~~~~~~~~~~~~
trace "Hello World from FAKE"
)
RunTargetOrDefault "Default"
I appreciate if anyone can give me any advice.
I'm using VS Code on Mac with Mono 4.2.1.
And my paket.lock looks like below:
NUGET
remote: https://www.nuget.org/api/v2
specs:
FAKE (4.21.0)
FSharp.Core (4.0.0.1)
FsUnit (2.0.0)
FSharp.Core (>= 3.1.2.5)
NUnit (3.0.1)
NUnit (3.0.1)
This happens because the module FscHelper defines a constructor called Target (see source), and that constructor conflicts with the Target function from the TargetHelper module. There is an issue filed about it.
Until the issue is fixed, there are three ways to work around this ambiguity:
Don't open FscHelper, just use all its innards in a qualified manner (e.g. FscHelper.Compile etc.)
Re-alias the TargetHelper.Target function in the local scope:
open Fake
open Fake.FscHelper
let Target = TargetHelper.Target
Target "Default" (fun _ ->
trace "Hello World from FAKE"
)
Reorder the open statements:
open Fake.FscHelper
open Fake
And since you're using this helper, note that the documentation for it is outdated. In particular, the Fsc task is deprecated in favor of the Compile task (see source).
Change the order of the open statements
#r #"packages/FAKE/tools/FakeLib.dll"
open Fake.FscHelper
open Fake
Target "a" (fun _ ->
["a.fs"] |> Compile []
The order of your open statements determines the precedence of the name resolution with the later opened modules and namespaces taking precedent.
I am working through the Embedding F# Interactive example from http://fsharp.github.io/FSharp.Compiler.Service/interactive.html but am having an issue with the following line throwing an exception:
let fsiSession = FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, outStream, errStream)
The exception thrown is:
"An unhandled exception of type 'System.Exception' occurred in FSharp.Compiler.Service.dll
Additional information: Error creating evaluation session: StopProcessing null"
My project is being run from VS2015 Enterprise Update 1, setup as a simple F# console app, with Target F# runtime being F# 4.0 with the Target Framework as 4.6. The version of FSharp.Compiler.Service downloaded from nuget is 2.0.0.2.
The Program.Fs file code I am running is here (a direct port of the example):
open System
open System.IO
open System.Text
open Microsoft.FSharp.Compiler.SourceCodeServices
open Microsoft.FSharp.Compiler.Interactive.Shell
[<EntryPoint>]
let main argv =
let sbOut = new StringBuilder()
let sbErr = new StringBuilder()
let inStream = new StringReader("")
let outStream = new StringWriter(sbOut)
let errStream = new StringWriter(sbErr)
// Build command line arguments & start FSI session
let argv = [| "C:\\fsi.exe" |]
let allArgs = Array.append argv [|"--noninteractive"|]
let fsiConfig = FsiEvaluationSession.GetDefaultConfiguration()
let fsiSession = FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, outStream, errStream)
/// Evaluate expression & return the result
let evalExpression text =
match fsiSession.EvalExpression(text) with
| Some value -> printfn "%A" value.ReflectionValue
| None -> printfn "Got no result!"
evalExpression "42+1" // prints '43'
Console.ReadLine() |> ignore
0 // return integer
Any thoughts would be appreciated.
The key to your problem is found at Compiler Services: Notes on FSharp.Core.dll
If doing dynamic compilation and execution you may also need to
include an FSharp.Core.optdata and FSharp.Core.sigdata, see below for
guidance.
When you build the application the output directory with FSharp.Core.dll is missing two files:
FSharp.Core.optdata
FSharp.Core.sigdata
You will need to find these two files and the correct versions of the files that agree with FSharp.Core.dll and copy them to the build output directory.
How to find the files using Visual Studio
From menu View -> Solution Explorer
Expand Project
Expand References
Right click FSharp.Core and select properties.
The Full Path gives the directory that should have at least the three files.
Use a file explorer to open the directory in Full Path.
Copy the two files
FSharp.Core.optdata
FSharp.Core.sigdata
to the build directory.
How to find the build directory using Visual Studio
From menu View -> Solution Explorer
Select Project
Press F4 to open the Properties Page
The Project Folder with \bin\Debug is the default when debugging with VS.
Change location of fsi.exe
Now that you have the two needed files you will also need to change the location of fsi.exe
let argv = [| "C:\\fsi.exe" |]
because I doubt that fsi.exe is in the root of your C drive.
I am getting this when trying to parse a simple csv string. I am running F# out of VS 2013, the dll says it is version 4.3.0.1 which I thought was F# 3.1. My Fsharp.Data dll is 1.1.10.
I am trying to run this as part of an nunit test using resharper. The snippet does work in interactive mode.
Here is the code:
open FSharp.Data
type TestCsv = CsvProvider<"test,taht\n1,1">
let x = TestCsv.Parse "test,taht\n1,1"
let tests = x.Data |> Seq.map (fun x -> x.test)
tests |> Seq.head
And the result:
System.Exception : Couldn't parse row 1 according to schema: Method not found: 'Microsoft.FSharp.Core.FSharpOption`1<System.String> FSharp.Data.RuntimeImplementation.Operations.AsOption(System.String)'.
Any ideas how to fix this?
FSharp.Data 1.1.10 doesn't support F# 3.1/VS2013. Please try with the prerelease version 2.0.0-alpha3 and let us if that works. Make sure both the unit test project and the library project are using the same version of FSharp.Core (either 4.3.0.0 or 4.3.1.0)