我创建了一个使用 F# 和 ReactiveUI 的 Xamarin Android 项目。
加载仪表板时,我在此代码段的 inherit
行遇到运行时异常(类型为 MissingMethodException
):
type DashboardViewModel(?host: IScreen) =
inherit ReactiveViewModel()
let host = LocateIfNone host
member __.Title with get() = "Dashboard"
interface IRoutableViewModel with
member __.HostScreen = host
member __.UrlPathSegment = "Dashboard"
错误消息为
Method 'Microsoft.FSharp.Quotations.FSharpExpr.Deserialize40' not found.
ReactiveViewModel
类型是 ReactiveObject
的薄包装:
type ReactiveViewModel() as this =
inherit ReactiveObject()
let mutable message = noMessage
let uiContext = SynchronizationContext.Current
member __.SyncContext with get() = uiContext
member this.Message
with get() = message
and set(value) =
this.RaiseAndSetIfChanged(&message, value, "Message") |> ignore
if message <> noMessage then this.RaiseAndSetIfChanged(&message, noMessage, "Message") |> ignore
member val MessageSent =
this.WhenAnyValue(toLinq <@ fun vm -> vm.Message @>).ObserveOn(RxApp.MainThreadScheduler).Where(fun m -> m <> noMessage) with get
该项目是开源的:目前,它包含的内容很少。可以在 https://github.com/SpiegelSoft/Astrid 找到。 .
我已在 Xamarin 错误跟踪器上提交了错误:https://bugzilla.xamarin.com/show_bug.cgi?id=51000
是否有任何我可以自己实现的已知修复,以便我可以自行关闭该错误?
更新1
这个周末我一直在调查这个问题。
加载的 FSharp.Core 版本停留在过时的版本 2.3.98.1 上。这对应于
中的FSharp.Core.dll
文件
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0
我尝试删除此版本并加载 NuGet 包 FSharp.Core;但是,当我构建 Android 项目时,路径始终恢复为引用程序集路径中过时的文件。
有办法重写这种行为吗?
更新2
替换Reference Assemblies
路径中的FSharp.Core.dll
文件可以解决这个问题,但是这是一个非常不令人满意的膏药,我不能问我的用户来申请。理想情况下,我希望找到一种方法来防止 .Droid
项目从 GAC 而不是 NuGet 包加载 FSharp.Core
。
最佳答案
前几天我刚刚遇到了一个非常相似的问题。我的 Android 应用程序引用了 Profile7 F# PCL 库,该库使用了 List.unfold,我相信它是在 F# 4 中引入的。当我在应用程序中使用该库时,我看到了与您所看到的类似的 MissingMethodException。创建新的 Android 应用程序时 Xamarin 默认引用的 FSharp.Core 版本没有此较新的方法。我通过编辑应用程序的 .fsproj 文件来删除对 FSharp.Core 的原始引用,并将其替换为对新版本的引用(我从 PCL .fsproj 文件复制/粘贴标签)来解决这个问题。它看起来像这样:
<Reference Include="FSharp.Core">
<Name>FSharp.Core</Name>
<Private>True</Private>
<AssemblyName>FSharp.Core.dll</AssemblyName>
<HintPath>$(MSBuildExtensionsPath32)\..\Reference Assemblies\Microsoft\FSharp\.NETCore\$(TargetFSharpCoreVersion)\FSharp.Core.dll</HintPath>
</Reference>
我惊讶地发现这似乎解决了我的问题。我不确定接下来是否会遇到其他问题,但如果您还没有遇到过,那么可能值得尝试一下。
更新如果这不能立即起作用,请按照 Rob Lyndon 的回答中的步骤顺序进行操作。
关于android - 使用 Xamarin Android 与 F# 和 ReactiveUI 时出现运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41445201/