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