c# - 在通用 Windows 中将 IEnumerable 更改为 IQueryable 时出现 MissingRuntimeArtifactException

标签 c# windows-10 win-universal-app .net-4.6

在 Release模式下,使用抛出 System.Reflection.MissingRuntimeArtifactException 的 AsQueryable 方法将 IEnumerable 源更改为 IQueryable。这是代码在 Debug模式下工作正常,请引用下面的代码片段。

    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();
    }

这个异常有什么解决办法吗?

最佳答案

将以下行添加到 <Application>运行时指令文件中的节点(通常称为 Default.rd.xml,位于 Properties 文件夹中)。

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

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

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

<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>

关于c# - 在通用 Windows 中将 IEnumerable 更改为 IQueryable 时出现 MissingRuntimeArtifactException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31537613/

相关文章:

node.js - npm 安装失败,错误 : EPERM: operation not permitted, 取消链接 '\node_modules'

c# - UWP 覆盖样式属性而不丢失其他属性定义

c# - 如何测量 UWP 应用程序中的文本大小?

c# - 在 Windows IOT Core UWP 中获取麦克风的输入电平

javascript - 将 Razor 字符串变量转换为 MVC 中的 Javascript 字符串变量

c# - javascript 请求.QueryString

c# - 无法使用数据注释

c - 如何在 Windows-10 的 C 控制台程序中获取鼠标输入?

visual-studio-2015 - 在 Windows 10 版本中找不到 SettingsPane

c# - 快速从数据表中删除在另一个数据表中找不到的行