【问题标题】:UWP app errors when built in .Net Native内置 .Net Native 时出现 UWP 应用程序错误
【发布时间】:2016-05-28 08:15:41
【问题描述】:

我们已将一个 Windows 8.1 应用转换为 Windows 10 UWP 应用。该应用程序在调试中运行良好,但在 Release (.Net Native) 中运行时,我们在应用程序加载时遇到运行时错误。目前还不清楚是什么导致了错误。该错误发生在 App.xaml.cs 中的 OnLaunched 事件中,其中一些数据正在初始化。错误:

System.NullReferenceException 类型的异常发生在 System.Private.CoreLib.dll

附加信息:Arg_NullReferenceException

我们正在使用最新版本的 MVVM Light。

我知道这不是很多信息,但它确实是我们现在拥有的所有信息,而且非常难过。任何人都见过这样的问题或知道从哪里开始追踪它?

【问题讨论】:

  • 您需要注意.Net Native 将尝试优化引用。所以它认为不需要的任何类型都将被省略。因此,如果您的代码或任何引用的库中发生任何反射,您需要将其显式添加回 rd.xml 文件中。更多信息dotnet.github.io/native/troubleshooter/type.html
  • 同样的问题,我发现这个错误是由第一次调用 Messenger.Default,Register 方法引起的,我试图为此添加一个指令,但仍然有那个错误:@ 987654322@@Depechie 有什么建议吗?
  • 抱歉,我不是解决 .net 原生错误的专家:/

标签: mvvm-light win-universal-app


【解决方案1】:

如果您仍在使用 SQLite 或任何参考。
请右键单击您的Project => Add => Reference => Make sure your DLL of Nuget 已选中。

请检查此解决方案。

【讨论】:

    【解决方案2】:

    我遇到了这个确切的问题,因为我将一个 8.1 应用程序转换为 UWP。这已通过在 Properties 文件夹中包含一个名为 Default.rd.xml 的文件来解决。我使用的迁移指南中没有提到这一点。

    不包括它意味着一些非常常见的编码模式(例如反射)将不起作用,这包括在导入的 .dll 中。

    基本的Default.rd.xml 文件如下所示...

    <!--
        This file contains Runtime Directives used by .NET Native. The defaults here are suitable for most
        developers. However, you can modify these parameters to modify the behavior of the .NET Native
        optimizer.
    
        Runtime Directives are documented at https://go.microsoft.com/fwlink/?LinkID=391919
    
        To fully enable reflection for App1.MyClass and all of its public/private members
        <Type Name="App1.MyClass" Dynamic="Required All"/>
    
        To enable dynamic creation of the specific instantiation of AppClass<T> over System.Int32
        <TypeInstantiation Name="App1.AppClass" Arguments="System.Int32" Activate="Required Public" />
    
        Using the Namespace directive to apply reflection policy to all the types in a particular namespace
        <Namespace Name="DataClasses.ViewModels" Serialize="All" />
    -->
    
    <Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
      <Application>
        <!--
          An Assembly element with Name="*Application*" applies to all assemblies in
          the application package. The asterisks are not wildcards.
        -->
        <Assembly Name="*Application*" Dynamic="Required All" />
    
    
        <!-- Add your application specific runtime directives here. -->
    
    
      </Application>
    </Directives>
    

    如果这不起作用,请尝试创建一个新的空 UWP 项目以获取文件的最新格式。

    【讨论】:

      猜你喜欢
      • 2016-07-10
      • 2016-07-09
      • 2010-09-30
      • 1970-01-01
      • 2020-06-10
      • 1970-01-01
      • 1970-01-01
      • 2017-08-04
      • 1970-01-01
      相关资源
      最近更新 更多