Xamarin Studio for Mac在FSI中抛出异常-"似乎"没有加载核心F#libs



很抱歉收到这么长的错误消息!我想知道我的Xamarin或Mono安装是否有问题,它破坏了Xamarin上的FSI?违约Net运行时为Mono 4.6.2虽然我安装了Mono 4.8.0,但Xamarin在4.6.2 上运行

我想知道这些错误消息是否意味着FSI没有加载系统。绘图模块?为什么SOURCE_DIRECTOR似乎不起作用?.fsx文件中没有显示任何错误,但当加载到FSI中时,它不起作用。

我还安装了Visual Studio for Mac。我刚从F#(第3天)开始,这是我第一次尝试打开系统模块,所以我不知道它是否有效。我自己编写的基本函数将在FSI中进行评估。我正在考虑安装可能在某个地方搞砸了,不知道是否应该删除。Net、Xamarin和Mono,然后从头开始重新安装?Visual Studio有可能干扰Xamarin吗?

通过FSharp电视介绍课程,我正在运行以下错误

.fsx文件中的F#:

open System.Drawing
let bitmap = new Bitmap(32,32)
let path = __SOURCE_DIRECTORY__ + "/"
bitmap.Save (path + "large.png")

在FSI中加载整个代码块抛出:

System.Exception: Generic Error [GDI+ status: GenericError]
   at System.Drawing.GDIPlus.CheckStatus (System.Drawing.Status status) [0x0007a] in <1917aa1c39d94b1a91807b8cd9f03350>:0 
   at System.Drawing.Image.Save (System.String filename, System.Drawing.Imaging.ImageCodecInfo encoder, System.Drawing.Imaging.EncoderParameters encoderParams) [0x00043] in <1917aa1c39d94b1a91807b8cd9f03350>:0 
   at System.Drawing.Image.Save (System.String filename, System.Drawing.Imaging.ImageFormat format) [0x0004c] in <1917aa1c39d94b1a91807b8cd9f03350>:0 
   at System.Drawing.Image.Save (System.String filename) [0x00008] in <1917aa1c39d94b1a91807b8cd9f03350>:0 
   at (wrapper remoting-invoke-with-check) System.Drawing.Image:Save (string)
   at <StartupCode$FSI_0004>.$FSI_0004.main@ () [0x0003d] in <2545683d6122431b9ff3a69ce9ec460c>:0 
   at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in <8f2c484307284b51944a1a13a14c0266>:0

在FSI中仅加载SOURCE_DIRECTORY返回:

val it : string = "/"

这很奇怪,因为这不是正确的路径

加载线路:let bitmap = new Bitmap(32,32)

投掷:

Stopped due to error
 System.Exception: Operation could not be completed due to earlier error
 The type 'Bitmap' is not defined at 2,4

发送系统。FSI 图纸

投掷:

Stopped due to error
 System.Exception: Operation could not be completed due to earlier error
 The value, constructor, namespace or type 'Drawing' is not defined at 2,7

看起来您可能遇到了Mono错误。我发现了几个关于同一个bug的报告(尽管可能是几个不同的bug)。最有用的一个似乎是这个Github问题:https://github.com/gitextensions/gitextensions/issues/2226

我不知道这对你是否有帮助;这个问题似乎已经通过从Mono 3.2.8升级到当时可用的Mono的最新版本而得到解决。但您已经运行了最新版本的Mono,所以"升级到最新的Mono"可能不是解决您问题的建议。但这是我能给的最好的建议。

此外,在进行搜索时,我发现有几个人抱怨libgdiplus(Mono的GDIPlus API实现)在各种方面都有缺陷。因此,如果你不能让libgdiplus发挥作用,我可能会跳过System.Drawing的例子,转到教程的另一部分。

第页。S.下面是我第一次回答你的问题时写的内容,但后来我进行了实验,发现System.Drawing命名空间是自动加载到F#脚本中的,而不需要显式打开它。不过,作为F#初学者,你可能会发现下面的信息在其他情况下很有用,所以我把它留了下来。请注意,我在下面所说的System.Drawing没有自动打开是错误的。

-----下面的答案不太正确----

.fsx文件中编写F#脚本时,不能只执行open (namespace)。您还必须告诉F#在哪里可以找到。具有该命名空间的DLL。在已编译的项目(使用.fs文件)中,该信息可以在.fsproj文件中找到。但对于F#脚本(.fsx格式),没有项目文件,因此脚本本身需要指定要加载的DLL。您可以通过#r指令来执行此操作:

#r "/path/to/library.dll"

或者,如果您正在加载的DLL安装在标准系统位置,如GAC(全局程序集缓存),您可以离开路径,只需执行以下操作:

#r "library.dll"

每当运行F#脚本时,都会自动加载一些DLL,例如mscorlib.dll,其中包含类似System命名空间的内容。但是System.Drawing命名空间并不是自动加载的DLL之一。因此,在打开System.Drawing命名空间之前,必须放入适当的#r引用,如下所示:

#r "System.Drawing.dll"
open System.Drawing

最新更新