MissingRuntimeArtifactException while changing IEnumerable to IQueryable in Universal Windows

点点圈 提交于 2020-01-03 16:56:07

问题


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?


回答1:


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

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


来源:https://stackoverflow.com/questions/31537613/missingruntimeartifactexception-while-changing-ienumerable-to-iqueryable-in-univ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!