Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

The compiler avoids dealing with things that don't resolve and we have handling for those in place to turn them into runtime exceptions.

We hit a situation when it doesn't kick in:

  • We're working with a nested type that is fine, but it's owning type is not (it implements an interface that doesn't resolve).
  • The protections within the compiler kick in and avoid bringing the containing type into compilation.
  • Once we're done compiling, we need to generate native reflection metadata for the nested type and that requires generating native metadata for the owning type. We don't have protections there because it's too late to do anything about it.

I'm adding code that skips problematic parts of the metadata.

This is a slight compat problem because doing a typeof(NestedType).DeclaringType would throw on JIT-based CoreCLR, but will now succeed on NativeAOT-based CoreCLR. The returned type will have an empty interface list. The compat in this corner case probably doesn't matter much.

The compiler avoids dealing with things that don't resolve and we have handling for those in place to turn them into runtime exceptions.

We hit a situation when it doesn't kick in:

* We're working with a nested type that is fine, but it's owning type is not (it implements an interface that doesn't resolve).
* The protections within the compiler kick in and avoid bringing the containing type into compilation.
* Once we're done compiling, we need to generate native reflection metadata for the nested type and that requires generating native metadata for the owning type. We don't have protections there because it's too late to do anything about it.

I'm adding code that skips problematic parts of the metadata.

This is a slight compat problem because doing a `typeof(NestedType).DeclaringType` would throw on JIT-based CoreCLR, but will now succeed on NativeAOT-based CoreCLR. The returned type will have an empty interface list. The compat in this corner case probably doesn't matter much.
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MichalStrehovsky MichalStrehovsky merged commit 7550df8 into dotnet:main Feb 3, 2022
@MichalStrehovsky MichalStrehovsky deleted the resilientnested branch February 3, 2022 05:44
@ghost ghost locked as resolved and limited conversation to collaborators Mar 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants