【问题标题】:Is possible to get usefull exceptions in xamarin.forms + F#?是否有可能在 xamarin.forms + F# 中获得有用的异常?
【发布时间】:2015-04-21 01:16:03
【问题描述】:

我正在测试将 Xamarin.Forms + F# 用于辅助项目的可行性。当事情奏效时,很棒。但是当代码有问题时,我总是会得到这个异常:

System.TypeInitializationException: An exception was thrown by the type initializer for <StartupCode$BestSellerPOS>.$Forms

不管错误发生的原因。所以,我需要从一开始就一步一步地处理每一行,看看发生了什么。

这次这是完整的异常(这已经发生了好几次了,但我没有记录之前的错误,看看是否是相同的确切回溯...只记得是相同的初始例外):

System.TypeInitializationException: An exception was thrown by the type initializer for <StartupCode$BestSellerPOS>.$Forms ---> System.Exception: Missing or incorrect header for method .cctor
  --- End of inner exception stack trace ---
  at BestSellerPOS.Forms.get_mainForm () [0x00000] in <filename unknown>:0
  at BestSellerPOS.App.get_FormDocs () [0x00000] in /Users/mamcx/Proyectos/BestSeller/BestSellerNET/Core/App.fs:7
  at BestSellerPOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x0001c] in /Users/mamcx/Proyectos/BestSeller/BestSellerNET/iOS/AppDelegate.fs:16
  at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
  at BestSellerPOS.Main.main (System.String[] args) [0x00000] in /Users/mamcx/Proyectos/BestSeller/BestSellerNET/iOS/AppDelegate.fs:23

我有所有东西的最新版本,在优胜美地。

警察局:

我已经设置了一个具有最少编码的空白解决方案,并在启动时强制除以零错误。仍然没有收到该错误,而是一条通用消息。

然后创建另一个黑色解决方案,这一次,没有共享项目,完全按照 xamarin ios 模板提供的方式。这给出了一个很好的例外,并指向确切的位置!

【问题讨论】:

    标签: exception f# xamarin xamarin.forms


    【解决方案1】:

    在 F# 中,当 module 初始化期间发生异常时,您会得到 TypeInitializationException。这表明,let-bound 值在某处爆炸。如果没有看到代码,就很难准确说出它发生在哪里。

    但解决方案通常意味着从初始化期间执行的let 绑定值更改为通过在几个关键位置添加say () 并将执行推迟到更有意义的时间来处理根据需要例外。或者,您可以将您的值声明为 lazy 并使用它来推迟执行。

    一般来说,我建议不要在 module 初始化期间出现异常,因为模块初始化发生的时刻并不容易预测。

    【讨论】:

    • 嗨,是的,我发现了。我删除了这种功能的所有痕迹,仍然得到错误。但是,问题是:存在一种方法来知道究竟是什么导致了异常,因为在黑暗中拍摄并不好。这是 F#、Mono、Xamarin 的问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 1970-01-01
    • 2011-01-27
    • 2011-12-10
    • 2020-01-13
    • 2018-07-25
    • 2019-02-12
    相关资源
    最近更新 更多