本文介绍了在通用 Windows 中将 IEnumerable 更改为 IQueryable 时出现 MissingRuntimeArtifactException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在发布模式下,同时使用抛出 System.Reflection.MissingRuntimeArtifactException 的 AsQueryable 方法将 IEnumerable 源更改为 IQueryable.这是代码在调试模式下工作正常,请参考下面的代码片段.

In Release mode, while changing the IEnumerable source to IQueryable using AsQueryable method which throws System.Reflection.MissingRuntimeArtifactException. This is code is working fine in Debug mode, please refer the below code snippet.

    ObservableCollection<object> data;
    IEnumerable source;
    public MainPage()
    {
        this.InitializeComponent();
        data = new ObservableCollection<object>();
        source = data as IEnumerable;
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var querab1 = data.AsQueryable();
        var querab2 = source.AsQueryable();
    }

有没有针对这个异常的解决方案?

Is there any solution for this exception?

推荐答案

将以下行添加到运行时指令文件(通常称为 Default.rd.xml 并在 Properties 文件夹中找到).

Add the following line to the <Application> node in your runtime directives file (usually called Default.rd.xml and found in the Properties folder).

<Namespace Name="System.Linq" Dynamic="Required All" Serialize="Required All" XmlSerializer="Required All"/>

使用 Release 模式会调用 .NET Native 工具链.它在最终的应用程序集中只包含应用程序实际调用的代码.这会导致您的应用程序中不包含某些反射和后期绑定的调用代码.使用运行时指令文件允许您覆盖默认行为并包含所需的元数据和实现代码.

Using the Release mode invokes the .NET Native tool chain. It includes in the final app assembly only that code that is actually invoked by the app. This causes certain reflection and late-bound invocation code to not be included in your app. Using the runtime directives file allows you to override the default behavior and include the required metadata and implementation code.

PS:您的运行时指令文件应如下所示:

PS: Your runtime directives file should look something like this:

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Application>
    <Assembly Name="*Application*" Dynamic="Required All" />
    <Namespace Name="System.Linq" Dynamic="Required All" Serialize="Required All" XmlSerializer="Required All" />
  </Application>
</Directives>

这篇关于在通用 Windows 中将 IEnumerable 更改为 IQueryable 时出现 MissingRuntimeArtifactException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 13:13
查看更多