【问题标题】:Error on LoadApplication in Xamarin Forms PCLXamarin Forms PCL 中的 LoadApplication 错误
【发布时间】:2018-08-11 10:18:50
【问题描述】:

我创建了一个新的Xamarin Forms PCL 解决方案,在调试模式下,我检查了Enable ProGuard 选项并选择了Linking 组合框到Sdk and User Assemblies。 现在我在 android 上运行我的应用程序,之后它在 MainActivity.cs 类和在线显示我一个错误

LoadApplication(new App());

错误:

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object.

我这样做是为了减小发布应用程序的大小,并且我必须将发布模式更改为调试以检查发生了什么。

【问题讨论】:

  • 我假设您使用的是 Xamarin 表单?请发布引发错误的代码行。我认为您的问题是您需要将其更改为LoadApplication(new PCLNameHere.App())
  • 我试过了,但它在 LoadApplication(new App());重要的一点是,当我将 Linking 选项更改为 none 并且未选中 ProGuard 选项时,我的应用程序成功运行。我需要这些选项来减少我的最终 .apk 文件
  • 堆栈跟踪的其余部分是什么意思?
  • 仅链接 SDK 程序集还不够?
  • @hvaughan3 我的 Environment.StackTrace 的值是:在 System.Environment.get_StackTrace () [0x00000] in :0 在 System.Diagnostics.Debugger.Mono_UnhandledException_internal (System.Exception) [ 0x00000]在:0在System.Diagnostics.Debugger.Mono_UnhandledException(System.Exception的前)[0x00000]在:0在System.Object.d09f62bf-1e4f-438B-810E-1b2febfe5330(System.IntPtr, System.IntPtr , System.IntPtr ) [0x00000] 在 :0

标签: c# android xamarin portable-class-library


【解决方案1】:

根据:The type or namespace 'App' does not exist in the current namespace

清理解决方案 构建 PCL 从受影响的项目中删除 PCL 引用 重新添加 PCL 参考 构建

我尝试了这个解决方案,它确实有效。

【讨论】:

    【解决方案2】:

    查看您的 App.xaml.cs 文件。 如果出现“InitializeComponent does not exist in the current context 错误”,这很可能是由已知的 VS 错误引起的。

    解决方案:

    • 右键单击 App.xaml.cs 并选择属性。
    • 将构建操作更改为“内容”。
    • 申请。
    • 将 Build Action 改回 C# Compiler。
    • 清洁解决方案。
    • 构建和部署。

    【讨论】:

      猜你喜欢
      • 2017-06-24
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-29
      • 2014-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多