Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query on .NET Native: Improve metadata inference #3603

Closed
natemcmaster opened this issue Oct 29, 2015 · 2 comments
Closed

Query on .NET Native: Improve metadata inference #3603

natemcmaster opened this issue Oct 29, 2015 · 2 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@natemcmaster
Copy link
Contributor

Queries on UWP using the follow LINQ operators are likely to fail:

  • SelectMany
  • Join
  • GroupJoin
  • Include
  • Select

Queries that use anonymous types will also fail.

Most will fail with a MissingRuntimeArtifactException with a message such as :

System.Reflection.MissingRuntimeArtifactException: MakeGenericMethod() cannot create this generic method instantiation
because the instantiation was not metadata-enabled

The problem

By default, ILC (IL compilation step of .NET Native) drops all metadata necessary for reflection. Metadata can be included by specifying static rules called runtime directives.

These directives have two limitations leading to our query failures: (1) These compiler directives are static, so they cannot fully determine which metadata is needed at runtime. (2) Directives in our library cannot always retrieve the necessary metadata from user-code types.

Our directives attempt to infer some permutations of user-code types and EF's internal types but cannot cover all cases due the exponential number of permutations (e.g. attempting to infer all valid type arguments of .Join<T1, T2, T3, T4>() caused ILC to die after 10 minutes of hogging 2-3 GB of memory).

The workaround for users
When our inference fails, users can add their own directives. For example, if a query were to fail with this error message, they could add a directive to their project's rd.xml file shown below.

System.Reflection.MissingMetadataException: 'System.Collections.Generic.IEnumerable<Microsoft.Data.Entity.Query.EntityQueryModelVisitor.TransparentIdentifier<Sample.Post,System.Collections.Generic.IEnumerable<Sample.Blog>>>
<TypeInstantiation Name="System.Collections.Generic.IEnumerable"
    Arguments="Microsoft.Data.Entity.Query.EntityQueryModelVisitor.TransparentIdentifier{Sample.Post, System.Collections.Generic.IEnumerable{Sample.Blog}}" 
    Dynamic="Required All" />

This has limits however, as directives do not support anonymous types.

Solutions
Improve our directives to reduce the number of directives users must add to make their queries work on UWP.

Use reflection less.

Use reference-type constraints on generic methods. This eliminates the need to properly combine user-types and EF types. Inference with "System.Object" produces metadata than the runtime automatically reuses.

@rowanmiller rowanmiller changed the title Improve metadata inference for .NET Native Query on .NET Native: Improve metadata inference Oct 30, 2015
@rowanmiller rowanmiller added this to the 7.0.0 milestone Oct 30, 2015
@natemcmaster
Copy link
Contributor Author

Improve coverage of generate runtime directives for queries using TransparentIdentifier and anonymous types

Left over from #4197. This should help solve most of the problems identified in this issue.

@natemcmaster
Copy link
Contributor Author

🎉 don't need to do this anymore. #4618

@divega divega added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

3 participants