I am getting an error when trying to build a simple F# project on macOS High Sierra.
$ mono --version
Mono JIT compiler version 5.0.1.1 (2017-02/5077205 Sun Sep 17 18:29:46 BST 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: normal
SIGSEGV: altstack
Notification: kqueue
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen (concurrent by default)
Steps:
Open VS Code
Ionide New F# Project
Choose the Suave Project Template
$ mono .paket/paket.exe install
$ ./build.sh
The error is:
1) System.Exception: dotnet build failed
at FSI_0005.Build+runDotnet#40.Invoke (System.String message) [0x00001] in <c9993ec69ddb4848af99438005012ea7>:0
at Microsoft.FSharp.Core.PrintfImpl+StringPrintfEnv`1[TResult].Finalize () [0x00012] in <5893d081904cf4daa745038381d09358>:0
at Microsoft.FSharp.Core.PrintfImpl+Final1#224[TState,TResidue,TResult,A].Invoke (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] env, A a) [0x00038] in <5893d081904cf4daa745038381d09358>:0
at Microsoft.FSharp.Core.OptimizedClosures+Invoke#3253[T2,TResult,T1].Invoke (T2 u) [0x00001] in <5893d081904cf4daa745038381d09358>:0
at FSI_0005.Build.runDotnet (System.String workingDir, System.String args) [0x00048] in <c9993ec69ddb4848af99438005012ea7>:0
at FSI_0005.Build+clo#64-6.Invoke (System.String p) [0x0000a] in <c9993ec69ddb4848af99438005012ea7>:0
at Microsoft.FSharp.Collections.SeqModule.Iterate[T] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] action, System.Collections.Generic.IEnumerable`1[T] source) [0x0002d] in <5893d081904cf4daa745038381d09358>:0
at FSI_0005.Build+clo#62-5.Invoke (Microsoft.FSharp.Core.Unit _arg4) [0x0000b] in <c9993ec69ddb4848af99438005012ea7>:0
at Fake.TargetHelper+targetFromTemplate#209-1[a].Invoke (Microsoft.FSharp.Core.Unit unitVar0) [0x00001] in <59b649fdccf1c534a7450383fd49b659>:0
at Fake.TargetHelper.runSingleTarget (Fake.TargetHelper+TargetTemplate`1[a] target) [0x0004b] in <59b649fdccf1c534a7450383fd49b659>:0
How can I get this working?
Ionide did not pick the correct target framework by default.
You need to make the following changes:
To *.fsproj, change the target framework to:
<TargetFramework>netcoreapp2.0</TargetFramework>
To paket.dependencies, change the framework to:
framework: >= netcoreapp2.0
Run Paket again:
$ mono .paket/paket.exe install
Run the build script again:
$ ./build.sh
Related
Running the current Preview channel of Visual Studio Mac, v8.3 build 1630, my Xamarin.Android app reports a Newtonsoft.Json.JsonReaderException.
The code below works fine in the current Stable channel of Visual Studio for Mac, v8.2.6 (build 28).
Do I need to update something for VS for Mac v8.3?
Code
readonly static HttpClient _client = new HttpClient();
public static async Task<MyModel> GetModelFromApi()
{
using (var response = await _client.GetAsync("https://my.api.url/endpoint").ConfigureAwait(false))
{
var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<MyModel>(json);
}
}
Stack Trace
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: �. Path '', line 0, position 0.Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: �. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue () [0x002b3] in <12891e825fce44a581e5bbbb579c1d49>:0
at Newtonsoft.Json.JsonTextReader.Read () [0x0004c] in <12891e825fce44a581e5bbbb579c1d49>:0
at Newtonsoft.Json.JsonReader.ReadAndMoveToContent () [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0
at Newtonsoft.Json.JsonReader.ReadForType (Newtonsoft.Json.Serialization.JsonContract contract, System.Boolean hasConverter) [0x0004a] in <12891e825fce44a581e5bbbb579c1d49>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <12891e825fce44a581e5bbbb579c1d49>:0
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00054] in <12891e825fce44a581e5bbbb579c1d49>:0
at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <12891e825fce44a581e5bbbb579c1d49>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0
at JsonParseTextRepro.ApiService.GetPun () [0x0013f] in <a23104cc471e42a78acea59e0c31e721>:0
at JsonParseTextRepro.App+DemoPage.OnAppearing () [0x00091] in <a23104cc471e42a78acea59e0c31e721>:0
Environment Info
=== Visual Studio Enterprise 2019 for Mac (Preview) ===
Version 8.3 Preview (8.3 build 1630)
Installation UUID: 6e5142b4-e8be-4d1c-b75e-4744b0d8c3de
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.16.1.24 (d16-3 / 08809f5b)
=== Xamarin.Android ===
Version: 10.0.0.40 (Visual Studio Enterprise)
Commit: xamarin-android/d16-3/080eaac
Android SDK: /Users/brandonm/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
None installed
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.2
SDK Build Tools Version: 28.0.3
Build Information:
Mono: mono/mono#6434153
Java.Interop: xamarin/java.interop#5836f58
LibZipSharp: grendello/LibZipSharp/d16-3#71f4a94
LibZip: nih-at/libzip#b95cf3f
ProGuard: xamarin/proguard#905836d
SQLite: xamarin/sqlite#8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools#cb41333
Answer
This is a regression in the Managed Linker where it is incorrectly removing the Xamarin.Android.Net.AndroidClientHandler library.
The Xamarin team is aware of the issue and you can track the status of it here:
https://github.com/xamarin/xamarin-android/issues/3626
Work Around
To prevent the linker from removing the AndroidClientHandler library, you can add it to the Ignore assembles option in the Android Build settings.
I am fighting with a problem while installing opencv for Code Blocks.
I have installed MinGW with all necessary compilers and I'm trying to build binaries using CMake. I am setting code blocks MinGW makefiles as generator, and I am specyfing c and c++ compilers as x86_64-w64-mingw32-g++ and gcc. Yet I'm getting an error:
CMake Error: Error SetGlobalGenerator called with null
The CXX compiler identification is unknown
The C compiler identification is unknown
Check for working CXX compiler: C:/mingw-w64/mingw64/bin/x86_64-w64-mingw32-g++.exe
Check for working CXX compiler: C:/mingw-w64/mingw64/bin/x86_64-w64-mingw32-g++.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.7/Modules/CMakeTestCXXCompiler.cmake:44 (message):
The C++ compiler "C:/mingw-w64/mingw64/bin/x86_64-w64-mingw32-g++.exe" is
not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/openCV/new_build/CMakeFiles/CMakeTmp
Run Build Command:"C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe"
"cmTC_2867a.vcxproj" "/p:Configuration=Debug" "/p:VisualStudioVersion=14.0"
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 2016-10-12 14:20:38.
Project "C:\openCV\new_build\CMakeFiles\CMakeTmp\cmTC_2867a.vcxproj" on
node 1 (default targets).
PrepareForBuild:
Creating directory "cmTC_2867a.dir\Debug\".
Creating directory "C:\openCV\new_build\CMakeFiles\CMakeTmp\Debug\".
Creating directory "cmTC_2867a.dir\Debug\cmTC_2867a.tlog\".
InitializeBuildStatus:
Creating "cmTC_2867a.dir\Debug\cmTC_2867a.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
CL.exe /c /W1 /WX- /O2 /Oy- /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_2867a.dir\Debug\\" /Fd"cmTC_2867a.dir\Debug\vc140.pdb" /Gd /TP /analyze- /errorReport:queue C:\openCV\new_build\CMakeFiles\CMakeTmp\testCXXCompiler.cxx
TRACKER : error TRK0005: Failed to locate: "CL.exe". Nie mo�na odnale��
okre�lonego pliku.
[C:\openCV\new_build\CMakeFiles\CMakeTmp\cmTC_2867a.vcxproj]
Done Building Project
"C:\openCV\new_build\CMakeFiles\CMakeTmp\cmTC_2867a.vcxproj" (default
targets) -- FAILED.
Build FAILED.
"C:\openCV\new_build\CMakeFiles\CMakeTmp\cmTC_2867a.vcxproj" (default
target) (1) ->
(ClCompile target) ->
TRACKER : error TRK0005: Failed to locate: "CL.exe". Nie mo�na odnale�� okre�lonego pliku. [C:\openCV\new_build\CMakeFiles\CMakeTmp\cmTC_2867a.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.11
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:93 (project)
Configuring incomplete, errors occurred!
See also "C:/openCV/new_build/CMakeFiles/CMakeOutput.log".
See also "C:/openCV/new_build/CMakeFiles/CMakeError.log".
I have path for MinGW bin folder created, yet there's a problem with compiler. I installed windows JDK8.1 (previously in error window it was said that I need to install it).
According to the FAKE documentation you can list all existing targets in your build file by executing FAKE with the argument --listTargets (or alternatively -lt):
> ./build.sh --listTargets
build.sh is a wrapper script from ProjectScaffold.
https://fsharp.github.io/FAKE/specifictargets.html
My version of FAKE is:
> ./build.sh --version
FakePath: ...
FAKE - F# Make "4.16.1"
When I run the listTarget command I get a strange output:
Error parsing command line arguments. You have a mistake in your args, or are using the pre-2.1.8 argument style:
Exception Message:unrecognized argument: '--listTargets'.
At the end of the error message I get the information I wanted:
Attempting to run with pre-version 2.18 argument style, for backwards compat.
Available targets:
- Clean
Depends on: []
- Build
Depends on: ["Clean"]
- CopyBinaries
Depends on: ["Build"]
- RunTests
Depends on: ["CopyBinaries"]
- Default
Depends on: ["RunTests"]
From the error message I get the impression that something changed in version 2.1.8 according to the argument style.
My question: What is the correct way to list all existing targets with FAKE?
Here is the complete output:
> ./build.sh --listTargets
No version specified. Downloading latest stable.
Paket.exe 2.47.1.0 is up to date.
Paket version 2.47.1.0
0 seconds - ready.
Error parsing command line arguments. You have a mistake in your args, or are using the pre-2.1.8 argument style:
Exception Message:unrecognized argument: '--listTargets'.
--envvar [-ev] <string> <string>: Set environment variable <name> <value>. Supports multiple.
--envflag [-ef] <string>: Set environment variable flag <name> 'true'. Supports multiple.
--logfile [-lf] <string>: Build output log file path.
--printdetails [-pd]: Print details of FAKE's activity.
--version [-v]: Print FAKE version information.
--fsiargs [-fa] <string> ...: Pass args after this switch to FSI when running the build script.
--boot [-b] <string> ...: Boostrapp your FAKE script.
--break [-br]: Pauses FAKE with a Debugger.Break() near the start
--single-target [-st]: Runs only the specified target and not the dependencies.
--nocache [-nc]: Disables caching of compiled script
--help [-h|/h|/help|/?]: display this list of options.
**************************************************
Type: System.ArgumentException
HResult: -2147024809
Source: Argu
TargetSite: Nessos.Argu.ParseResults`1[Cli+FakeArg] Nessos-Argu-IExiter-Exit[ParseResults`1](System.String, Microsoft.FSharp.Core.FSharpOption`1[System.Int32])
StackTrace
**************************************************
at Nessos.Argu.ExceptionExiter.Nessos-Argu-IExiter-Exit[b] (System.String msg, Microsoft.FSharp.Core.FSharpOption`1 _arg1) <0x30ab2b8 + 0x00027> in <filename unknown>:0
at Nessos.Argu.ArgumentParser`1[Template].Parse (Microsoft.FSharp.Core.FSharpOption`1 inputs, Microsoft.FSharp.Core.FSharpOption`1 xmlConfigurationFile, Microsoft.FSharp.Core.FSharpOption`1 errorHandler, Microsoft.FSharp.Core.FSharpOption`1 ignoreMissing, Microsoft.FSharp.Core.FSharpOption`1 ignoreUnrecognized, Microsoft.FSharp.Core.FSharpOption`1 raiseOnUsage) <0x2d47288 + 0x00332> in <filename unknown>:0
at Cli.parsedArgsOrEx (IEnumerable`1 args) <0x70a390 + 0x000cb> in <filename unknown>:0
Attempting to run with pre-version 2.18 argument style, for backwards compat.
Available targets:
- Clean
Depends on: []
- Build
Depends on: ["Clean"]
- CopyBinaries
Depends on: ["Build"]
- RunTests
Depends on: ["CopyBinaries"]
- Default
Depends on: ["RunTests"]
Update
I've just found a GitHub issue which reference my problem some how but I can make no sense of it:
https://github.com/fsharp/FAKE/issues/1082
I have installed FsUnit
» nuget install fsunit
Attempting to resolve dependency 'NUnit (≥ 2.6.3)'.
Installing 'NUnit 2.6.3'.
Successfully installed 'NUnit 2.6.3'.
Installing 'FsUnit 1.3.0.1'.
Successfully installed 'FsUnit 1.3.0.1'.
I have created simple unit test:
module Tests
open NUnit.Framework
open FsUnit
[<Test>]
let ``simple test`` () =
1 |> should equal 1
Here is I am launching my test:
» fsharpc -r NUnit.2.6.3/lib/nunit.framework.dll -r FsUnit.1.3.0.1/Lib/Net40/FsUnit.NUnit.dll 01_binomial_tests.fs
F# Compiler for F# 3.1 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
/Users/demas/development/book_exericses/fsharp_deep_dive/01_binomial_tests.fs(7,1): warning FS0988: Main module of program is empty: nothing will happen when it is run
It was compiled fine but I don't know how to launch the tests without VS
Update
I have tried to use NUnit.Runners:
> nuget install NUnit.Runners
> fsharpc -r NUnit.2.6.3/lib/nunit.framework.dll -r FsUnit.1.3.0.1/Lib/Net40/FsUnit.NUnit.dll --target:library 01_binomial_tests.fs
> mono NUnit.Runners.2.6.4/tools/nunit-console.exe 01_binomial_tests.dll
NUnit-Console version 2.6.4.14350
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.
Runtime Environment -
OS Version: Unix 14.4.0.0
CLR Version: 2.0.50727.1433 ( Mono 3.5 ( 3.10.0 ((detached/92c4884 Thu Nov 13 23:27:38 EST 2014) ) )
ProcessModel: Default DomainUsage: Single
Execution Runtime: mono-3.5
Could not load file or assembly '01_binomial_tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
You have a couple of options:
Add dependency on NUnit.Runners NuGet package, which comes with a stand-alone runner
Use Xamarin Studio, which seems to have Unit Tests panel for running tests
Use FAKE which is a nice F# build tool that can run unit tests
I personally use FAKE because it nicely automates everything. To do that, you need to put something like this in your FAKE build.fsx script:
Target "Test" (fun _ ->
!! "/tests*.dll |> NUnit (fun p ->
{p with
DisableShadowCopy = true;
OutputFile = testDir + "TestResults.xml" })
)
You'll need dependencies on FAKE and NUnit.Runners and then FAKE should also find the runner automatically (so you do not have to set it explicitly in your build script).
Here is a bit of code that won't win awards for complexity:
[<EntryPoint>]
let main argv =
let i = 1I
printfn "One is %A\n" i
0 // return an integer exit code
It's compiled as follows: "c:/Program Files (x86)/Microsoft SDKs/F#/3.0/Framework/v4.0/Fsc.exe" --out:numericstest.exe --debug:full --target:exe --standalone Program.fs
Under Windows it produces the expected result. However under Mono 3.0.7 compiled under Ubuntu it instead says:
mono numericstest.exe
Unhandled Exception: System.InvalidProgramException: Invalid IL code in System.Numerics.BigInteger:get_One (): method body is empty.
at Program.main (System.String[] argv) [0x00000] in <filename unknown>:0[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in System.Numerics.BigInteger:get_One (): method body is empty.
at Program.main (System.String[] argv) [0x00000] in <filename unknown>:0
What am I doing wrong please? Many thanks.
There's nothing wrong with your code -- that exception is due to your code anyway. It looks like there's something wrong with the System.Numerics.dll assembly on your machine; either it's not installed correctly, it's getting compiled incorrectly (e.g., by the Mono C# compiler), or it's doing some kind of type forwarding which is not working like it should, etc.
What happens if you run the code without using BigInteger (via the I suffix)?
I tried your code in my Ubuntu (12.04, 32-bit) VM running under VirtualBox. The code compiled and ran as expected. Here's the output if you want:
Compile/Run
jack#jack-linux:~/Desktop$ fsharpc --out:JoeHuha.exe --debug:full --target:exe --standalone JoeHuha.fs
F# Compiler for F# 3.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
jack#jack-linux:~/Desktop$ mono JoeHuha.exe
One is 1
Mono version info
jack#jack-linux:~/Desktop$ mono -V
Mono JIT compiler version 3.0.5 (master/1643364 Fri Feb 22 19:31:07 EST 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: x86
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)